[gdal-dev] Strange (expected?) behaviour exporting multipart geometry to ESRI Shapefile format
Andrea Giudiceandrea
andreaerdna at libero.it
Tue Feb 15 23:07:18 PST 2022
Hi GDAL devs,
trying find the root cause of a bug [1] reported in the QGIS GitHub
repository, I've noticed a strange behaviour when a multipart geometry
is exported to an ESRI Shapefile layer.
I've created a minimal GeoPackage layer file [2] which contains 1
multipart polygon geometry (MultiPolygon) feature consisting of 3 parts.
The 3 parts are 3 clockwise polygons external rings.
The following command for such GeoPackage layer:
ogrinfo Polygon_3.gpkg Polygon_3 -geom=SUMMARY
reports:
OGRFeature(Polygon_3):0
MULTIPOLYGON : 3 geometries:
POLYGON : 7 points
POLYGON : 9 points
POLYGON : 21 points
It seems to me something strange happens converting the GeoPackage layer
to an ESRI Shapefile layer using e.g:
ogr2ogr -f "ESRI Shapefile" Polygon_3.shp Polygon_3.gpkg
ogrinfo for the resulting ESRI Shapefile layer reports:
OGRFeature(Polygon_3):0
FID (Integer64) = 0
MULTIPOLYGON : 2 geometries:
POLYGON : 9 points
POLYGON : 21 points, 1 inner rings (7 points)
That is, the 7 points part has been written in the Shapefile layer as a
counter clockwise polygon and "attached" to the 21 points part (which
remains a clockwise polygon external ring) as his inner ring. The 9
points part remains a clockwise polygon external ring.
On the contrary, converting the GeoPackage layer to GML or FlatGeobuf or
GeoJSON or Spatialite formats, the resulting layer correctly contains 1
MultiPolygon feature consisting of 3 clockwise Polygon parts like the
original layer and ogrinfo reports:
OGRFeature(Polygon_3):0
MULTIPOLYGON : 3 geometries:
POLYGON : 7 points
POLYGON : 9 points
POLYGON : 21 points
I've checked the orientation of the polygons parts using QGIS 3.22.3 for
all the layers and also ArcMap/ArcGIS 9.3.1 for the Shapefile layer.
QGIS reports 3 parts for the geometry in the GeoPackage, GML,
FlatGeobuf, GeoJSON or Spatialite layers, while it reports 2 parts for
the ESRI Shapefile layer.
Is this an expected behaviour of the ESRI Shapefile driver writing
multipart features geometries?
Best regards.
Andrea Giudiceandrea
[1] https://github.com/qgis/QGIS/issues/47288
[2] https://drive.google.com/file/d/10HiCARTYJqhAXUckK43nU4MzV1wUbLg9
More information about the gdal-dev
mailing list