0

I'm facing a problem when using osgeo/gdal:ubuntu-small-3.2.1 docker image and running these commands on the Natural Earth vector dataset:

# Get and unzip the data 
# (inspired from https://github.com/mapbox/natural-earth-tm2/blob/master/util/setup_db.sh) 
wget -q -N http://naciscdn.org/naturalearth/packages/natural_earth_vector.sqlite.zip
unzip -o -d natural_earth_vector natural_earth_vector.sqlite.zip

# Then, insert data into PG using ogr2ogr:
ogr2ogr \
    -progress \
    -f Postgresql \
    -s_srs EPSG:4326 \
    -t_srs EPSG:3857 \
    -clipsrc -180 -85.05 180.1 85.05 \
    PG:"host=localhost port=5432 dbname=mydb user=postgres password=****" \
    -lco GEOMETRY_NAME=geometry \
    -lco OVERWRITE=YES \
    -lco DIM=2 \
    -nlt GEOMETRY \
    -overwrite \
    "natural_earth_vector/packages/natural_earth_vector.sqlite"

The PostgreSQL/PostGIS database I'm trying to inject this data into is based on postgis/postgis:11-3.1 docker image.

This is the error I have:

0ERROR 1: TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point 30.796820538582722 61.704133379158407 at 30.796820538582722 61.704133379158407

This seems to be the culprit watershed in that particular case.

But this error actually appears more than 1'000 thousands times on other geometries .
I'm not sure where to search for a fix. Any ideas?

If this helps, here is the GDAL version number from inside the container:

# ogr2ogr --version
GDAL 3.2.1, released 2020/12/29

This thread sounds related but it's from R: Getting TopologyException: Input geom 1 is invalid which is due to self-intersection in R? and I don't know, if it's the same error, how could I transpose the solution here.

10
  • Have you tried to do a buffer at 0 on all the layer ? – J. Monticolo Feb 20 at 14:20
  • How would you do that in bash? I cannot figure out some buffering option in ogr2ogr:gdal.org/programs/ogr2ogr.html – s.k Feb 20 at 14:35
  • 1
    I would rather use ogrinfo natural_earth_vector/packages/natural_earth_vector.sqlite -dialect SQLite -sql "UPDATE a_sqlite_table SET geometry = ST_MakeValid(geometry). – user30184 Feb 20 at 17:06
  • 1
    Test it for sure, a Geopackage is a Spatialite DB, so, spatial functions are inside (IMHO). – J. Monticolo Feb 21 at 8:37
  • 1
    GeoPackage is SQLite DB but not SpatiaLite DB. GeoPackage does not have native spatial functions, other than ST_MinX, ST_MinY, ST_MaxX, ST_MaxY, and ST_IsEmpty which are defined in the standard. GDAL adds a couple of functions gdal.org/drivers/vector/gpkg.html but for the most part the support of the SpatiaLite functions goes through the SQLite SQL dialect gdal.org/user/sql_sqlite_dialect.html. With SQLite dialect the functions like ST_MakeValid can be used for any datasource. – user30184 Feb 21 at 11:15

Your Answer

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

Browse other questions tagged or ask your own question.