I'm trying to create a layer of geometry type polygon, with a feature of geometry type polygon, and a geometry of type polygon. However, no matter how I attempt to set the geom type of the feature, geometry, or layer, the layer is always set to multipolygon.

Here is some example code to show what I mean:

# Create test polygon
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(1179091.1646903288, 712782.8838459781)
ring.AddPoint(1161053.0218226474, 667456.2684348812)
ring.AddPoint(1214704.933941905, 641092.8288590391)
ring.AddPoint(1228580.428455506, 682719.3123998424)
ring.AddPoint(1218405.0658121984, 721108.1805541387)
ring.AddPoint(1179091.1646903288, 712782.8838459781)
geom = ogr.Geometry(ogr.wkbPolygon)

print(geom.GetGeometryName()) # returns POLYGON

# Open the FGDB
driver = ogr.GetDriverByName("FileGDB")
path = "/path/to/polygon.gdb"
if not os.path.exists(path):
    data_source = driver.CreateDataSource(path)
    data_source = driver.Open(path, 1)

# Define the spatial reference to use
srs = osr.SpatialReference()

# Create the layer
layer_name = "polygon".encode("utf-8")
layer = data_source.CreateLayer(layer_name, srs, ogr.wkbPolygon)

print(ogr.GeometryTypeToName(layer.GetGeomType())) # returns Multi Polygon

# Create the feature
feat_def = ogr.FeatureDefn()
feature = ogr.Feature(feat_def)

print(ogr.GeometryTypeToName(feature.GetDefnRef().GetGeomType())) # returns Polygon

# Set the geometry

print(feature.GetGeometryRef().GetGeometryName()) # returns POLYGON

# Create the feature in the layer

# Dereference the feature
feature = None

# Save and close the data source
data_source = None
  • The first print, I show that the geometry I created is of type polygon

  • The second print, I show that the layer's geometry type is of multipolygon, despite me initializing the layer with type polygon.

  • The third print shows that I did set the feature's geometry type to polygon when explicitly creating a FeatureDefn

  • The fourth print shows that after setting the feature's geometry, it is still type polygon

Here's the output of ogrinfo:

$ ogrinfo polygon.gdb/ polygon
INFO: Open of `polygon.gdb/'
      using driver `OpenFileGDB' successful.

Layer name: polygon
Geometry: Multi Polygon
Feature Count: 1
Extent: (1161053.021823, 641092.828859) - (1228580.428456, 721108.180554)
Layer SRS WKT:
        SPHEROID["WGS 84",6378137,298.257223563,
Geometry Column = SHAPE
  MULTIPOLYGON Z (((1179091.16469033 712782.883845978 0,1218405.0658122 721108.180554139 0,1228580.42845551 682719.312399842 0,1214704.93394191 641092.828859039 0,1161053.02182265 667456.268434881 0,1179091.16469033 712782.883845978 0)))

I've looked everywhere in the (somewhat useless) OGR Python bindings API and have found nothing useful. So, how do I actually set the layer to be of geometry type polygon?

This is with Python 2.7.15 and GDAL 2.3.2 on CentOS 7.5.

  • 1
    Does FileGDB support Polygon and Multipolygon geometries as different things? Have you got a FileGDB somewhere that presents as "Polygon" and not "Multipolygon"? I can't find anything in the driver docs. And I don't have write-capability for FileGDB on Linux.... – Spacedman Oct 12 '18 at 19:05
  • Ahaha. Possible duplicate of gis.stackexchange.com/questions/173585/… – Spacedman Oct 12 '18 at 19:16
  • Ha, I see. What's funny is just as I was checking back on this question I was thinking "I wonder if FGDBs even support polygon vs multipolygon" because I had read about how shapefiles don't differentiate. Thanks for pointing it out to me – Drew Oct 12 '18 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.