2

I need to import geometries as they are (even invalid) into PostGIS. I use ogr2ogr in a Python script to import the shapefiles.

I was able to avoid most corrections removing the -makevalid option and adding -nlt GEOMETRY but I still get this warning:

Warning 1: mydata.shp contains polygon(s) with rings with invalid winding order. Autocorrecting them, but that shapefile should be corrected using ogr2ogr for example.

I think this autocorrection comes from the GDAL library. If possible, is there a way to tell GDAL not to autocorrect the geometries?

Or if not possible, does anyone know if this correction could alter the shape of the polygon in any way?

12
  • I looks like the geometries are invalid already in the shapefile, so not following the outer ring clockwise and holes counterclockwise rule esri.com/content/dam/esrisites/sitecore-archive/Files/Pdfs/…. Can you share a sample? Which software creates such shapefiles?
    – user30184
    Commented Apr 30 at 11:24
  • Yes, the geometries are invalid in the raw data. It comes from (poor quality) governmental data that needs to be imported as they are so that the import doesn't alter the official data. The shapefile can be downloaded here: cadastre.data.gouv.fr/data/etalab-cadastre/latest/shp/france/… I don't know the software they used to create it
    – Marc
    Commented Apr 30 at 11:46
  • 1
    Maybe you can import the shape as a geometryless table, with a select statement converting the geometry to WKT?
    – Bera
    Commented Apr 30 at 12:41
  • 1
    I don't agree with you about what is best. I think the best option is to contact the data provider and ask them to fix their data. Second best it to fix geometries on your side. And even it may be possible to keep the geometries untouched by saving them as WKT as suggested above, PostGIS and GDAL will correct and unify the winding order when data are saved into any GIS format.
    – user30184
    Commented Apr 30 at 12:43
  • 1
    $0.02: garbage IN, garbage OUT ... and let's not forget that different formats / software / functionalities can get distinctively artistic in how they handle geometric errors. What about fixing the geometries, then run a comparison between the original shapefile and the corrected layer then handle the cases - if any - where the correction introduce a visible difference. Beware if you have "right" and "left" attributes (though it is more common on lines than polygons)
    – JGH
    Commented Apr 30 at 14:14

1 Answer 1

4

Setting the OGR_ORGANIZE_POLYGONS configuration option to SKIP will avoid GDAL doing this interpretation.

However, if the ring ordering is not correct, the only thing gdal can do without any interpretation is to treat each ring as an outer ring, which I doubt is better than the default behaviour. The only thing GDAL does is reordering the points, so it is not a very intrusive change.

However, if you would want to use/try it, you can specify the option by adding these parameters:

--config OGR_ORGANIZE_POLYGONS SKIP
1
  • Thanks, I overlooked this option obviously! I will have a try
    – Marc
    Commented May 2 at 7:24

Your Answer

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

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