[GIS] GDAL/OGR (Python) GetGeomType() method returns integer, what is the matching geom type

gdalgeometryogropen-source-gispython

When I use the GetGeomType() with GDAL/OGR it returns an integer. I want to know what geometry type each integer represents.

driver = ogr.GetDriverByName("FileGDB")
gdb = r"C:\Users\******\Documents\ArcGIS\Default.gdb"
ds = driver.Open(gdb, 0)
input_lyr_name = "Birmingham_Burglaries_2016"
lyr = ds.GetLayerByName(input_lyr_name)
# access the schema info
lyr_def = lyr.GetLayerDefn()

print lyr_def.GetGeomType()

Output: 1

I already know an alternative way to get the geometry type as below, but I am interested to match integers to the correct geometry type. Is there a list somewhere?

first_feat = lyr.GetFeature(1)
print first_feat.geometry().GetGeometryName()

Output: POINT

But this won't work on an empty dataset.

Best Answer

If you need to determine the type in code, use the ogr.wkb* constants as per @iant's answer.

Alternatively, if you just want to print out the type, you can use the ogr.GeometryTypeToName function.

print ogr.GeometryTypeToName(lyr_def.GetGeomType())

e.g

In [1]: from osgeo import ogr

In [2]: print ogr.GeometryTypeToName(ogr.wkbPoint)
Point

In [3]: print ogr.GeometryTypeToName(ogr.wkbPolygon)
Polygon

In [4]: print ogr.GeometryTypeToName(ogr.wkbLineString)
Line String
Related Question