Hi,
Just wondering if this behavior is expected. I was confused why
OGR_G_GetGeometryRef() on a ring of a polygon could not be exported to
WKB. The reference to the ring reports as being a wkbLineString but
has WkbSize() of zero since it is really a wkbLinearRing. I would
expect GetGeometryType() to return 101 in that case.

If the reference is forced to a Polygon, the returned geometry has
non-zero WkbSize() and can be exported to WKB as expected.

However, if the reference is forced to LineString, the returned
geometry reports as wkbLineString but has WkbSize() of zero since it
is still a LinearRing.

# GDAL 3.11.3, GEOS 3.12.2
from osgeo import ogr

wkt = "POLYGON((2 49,3 49,3 48,2 49))"
g = ogr.CreateGeometryFromWkt(wkt)

# ref to ring of the polygon
g2 = g.GetGeometryRef(0)
g2.GetGeometryType()
# 2
g2.WkbSize()
# 0
g2.ExportToWkt()
# 'LINEARRING (2 49,3 49,3 48,2 49)'

# ref to ring forced to wkbPolygon
g3 = ogr.ForceTo(g2, ogr.wkbPolygon)
g3.GetGeometryType()
# 3
g3.WkbSize()
# 77
g3.ExportToWkt()
# 'POLYGON ((2 49,3 49,3 48,2 49))'

# ref to ring forced to wkbLineSTring
g4 = ogr.ForceTo(g2, ogr.wkbLineString)
g4.GetGeometryType()
# 2
g4.WkbSize()
# 0
g4.ExportToWkt()
# 'LINEARRING (2 49,3 49,3 48,2 49)'


Thanks.

Chris
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to