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?
Exported shapefile with filled holes marked by arrows
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)))
ogr2ogr
andpgsql2shp
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.