8

I am trying to convert a MULTIPOLYGON record from PostGIS (v2.2.2) to the shapefile via QGIS (v2.18.9), but the source geometry and the resulting shapefile do not match as displayed on the images below (the red layer is the source and the green layer is the resulting shapefile). I get the same result if I perform the conversion via ogr2ogr from GDAL v2.0.0. This conversion takes around 40 minutes to complete.

If I dump the source geometry to POLYGON and perform the conversion, the resulting shapefile is correct and the conversion is much faster (7 seconds + 17 seconds for dump). But, instead of 5 features, now I end up with 305188.

The source MULTIPOLYGON records are created by ST_Union on the adjacent cells if that matters.

Am I missing something? Is there a way to perform the correct conversion? Can anyone explain why is this happening?

Source geometry Source from PostGIS

Exported shapefile with filled holes marked by arrows Exported shapefile


I have more details:

pgsql2shp produces the same resulting shapefile like QGIS or ogr2ogr.

@dbaston - I did cut of most of the data and left the part around the area presented on the above images (around ('POINT(-89.45 29.99)',4326)). I converted this small sample and got the same result. If you or anybody wants to try the conversion on the same sample, you can get the dump here:

Sample data backup from PostgreSQL v9.5

After 31 hours, the ST_IsValid returned true on all geometry from the complete data set. I got the same result for the smaller sample available on the link above. However, Check validity in QGIS for the same smaller data set returned:

ring 1 of polygon 712 not in exterior ring  
ring 2 of polygon 712 not in exterior ring  
ring 3 of polygon 712 not in exterior...

How come there is a difference in the validity check in PostGIS and QGIS?

To check further, I removed all the polygon parts except the one marked blue on the image above. I checked its WKT format and it looks fine. And now the conversion to shapefile with only this feature was correct.

Does this make any sense? I did check more datasets created by ST_Union on the adjacent cells and found out that the same issue exists there too when converting to shapefile. The same data converted to GeoJSON produces the correct result.

MULTIPOLYGON was created from POLYGON geometry with the following expression:

st_multi(st_union(st_buffer(geom,0)))
6
  • 1
    There may be topology errors in the source data. Because data are in PostGIS you can check the geometries with ST_IsValid and ST_IsValidReason or correct them with ST_MakeValid.
    – user30184
    Oct 10, 2017 at 9:45
  • Sorry for not commenting here, but I do not have the privilege yet. I was wondering how you did: "I get the same result if I perform the conversion via ogr2ogr from GDAL v2.0.0" Could you be more specific.. code? Have you tried pgsql2shp?
    – Martinyt
    Oct 10, 2017 at 12:39
  • Thanks. I am running that now, but it is taking a really long time to check the geometry validity. I will respond when the check completes. Oct 10, 2017 at 13:00
  • 2
    I've seen this behavior before in (valid) complex geometries with nested rings inside of holes. These can be handled by both ogr2ogr and pgsql2shp differently, but I have seen cases that stump each of them. If you can reduce the problem to a smaller input, it would be useful as a bug report.
    – dbaston
    Oct 10, 2017 at 13:31
  • I converted your sample to GeoPackage and the result is the same as the Postgis. Do you really need to use shapefile format? Screenshot. GeoPackage is much better :-)
    – jgrocha
    Feb 24, 2018 at 12:15

1 Answer 1

1

It appears to be a bug in QGIS (2.18.16 included) when rendering the multipolygons from a SHP. If you open your SHP in ArcMap - this problem does not happen. Or, if you export your multipolygons to SQLite - this problem does not happen too. Hopefully someone from the QGIS team sees this question.

SHP using ArcMap 10 SQLite using QGIS 2.18.16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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