1

I have a problem when trying to export my Polygons with geopandas in shapefiles as Polygons. When I import the file later on in QGIS, they are analised as MultiPolygons.

I believe it is a tendency with the ESRI shapefile format, but is their a way around that permits to keep on with the shapefile format ? Or do I need to use another exporting format?

Here are some screenshots :

  1. Exporting with geopandasin Python. There appears to be no problem.

enter image description here

  1. Importing in QGIS. The features are imported as MultiPolygons instead of Polygons.

enter image description here

EDIT

The objective is to import this data to a PostGIS database using shp2pgsql. QGIS is a way to ensure that the shapefile indeed contains Polygons and not MultiPolygons. See screenshot below :

enter image description here

  • Testing if there are Polygons in the shapefile :

enter image description here

8
  • 1
    Does not seem to be a multipolygon shape type, see esri.com/library/whitepapers/pdfs/shapefile.pdf . Polygon type can have multiple outer rings. Maybe that is the way QGIS Always describes the geometry of polygon shapefiles? – BERA Apr 20 '20 at 12:16
  • 2
    What is the problem with them being multipolygons, what is your next step in QGIS? – BERA Apr 20 '20 at 12:22
  • Shapefile only distinguishes between Point and Multipoint (because they have different record types). It does not care if the Polylines are single- or multi-part or if the Polygons are single- or multi-part (it also doesn't care if rings are internal or external, assuming that the writer wrote them properly, using right hand rule). Any determination of Polygon would require a full file scan (MultiPolygon could be determined by the first feature with two exterior rings). This seems to be an artifact of QGIS assuming that all Polygon shapefiles are MultiPolygon until proven otherwise. – Vince Apr 20 '20 at 12:29
  • @BERA I think you are right. It seems that the problem is the opposite. I believe now that PostGIS wants the format MultiPolygon when my features are stored as Polygons in the shapefile. Could you confirm if this is true from the screenshot I have added please? Thanks for the feedback :) – AlexJew Apr 20 '20 at 14:22
  • You can do that in geopandas: any( 'Multipolygon' for row in df.geometry.type) – BERA Apr 20 '20 at 14:27
1

Because the Shapefile standard allows both Polygons and MultiPolygons to be stored in the same "Polygon" shapefile, programs that consider MultiPolygons to be different to Polygons have to "promote" Polygons from a Shapefile to MultiPolygons as you can never be sure what might be in the geometry attribute.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.