I'm trying to migrate GeoJSON data to PostGIS database and I thought that ogr2ogr is the tool:

ogr2ogr -f PostgreSQL PG:"host={} user={} port={} dbname={} password={}" test.geojson -nln ogr_test

However, the resulting PostGIS table contains geometry errors that were not present in GeoJSON file.

Using "Check geometry validity" from QGIS, shows that GeoJSON file is free of errors, but PostGIS layer that I converted with ogr2ogr contains multiple errors of this kind:

  • ring 3 of polygon 0 not in exterior ring
  • segment 2 of ring 11 of polygon 0 intersects segment 3 of ring 0 of polygon 0 at ...

with total 113 errors on 25 features.

Also issuing this query in pgAdmin:

FROM ogr_test
WHERE ST_IsValid(wkb_geometry) = 'f'

list 25 errors - the same number of feature errors as reported by QGIS command.

Then I converted my GeoJSON file to Shapefile. Testing the Shapefile for geometry errors, shows 9 errors on 2 features. Interestingly, the errors are on features that didn't produce errors while merged to PostGIS database.

Now I assume that ogr2ogr errors depend on destination format specifics, I'm interested as to why ogr2ogr produces these artifacts without informing the user, and what is the correct way to import GeoJSON to PostGIS?

I use GDAL 1.11.0

Actually it's again my fault - I used this script to check validity on GeoJSON files, as there were plenty of files to process. This script returned error only on one file which is not the test file used in this example. Loading GeoJSON in QGIS and checking validity, shows same errors.

So this seems my fault in arbitrary using multiple tools for validity check, and I'll vote this question to be close.


closed as off-topic by zetah, user30184, Erica, PolyGeo Sep 4 '14 at 11:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Erica, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Without a good sample of problematic source data it is impossible to answer. Errors in ring ordering makes me believe that there is still something odd in the source data. – user30184 Sep 4 '14 at 10:29
  • 1
    @user30184 ring errors are because I have many geometries where two separate rings create single feature and they are treated by ogr2ogr as polygons. If I convert these to multipolygon, errors are gone. – zetah Sep 4 '14 at 12:47