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.
ogrinfo natural_earth_vector/packages/natural_earth_vector.sqlite -dialect SQLite -sql "UPDATE a_sqlite_table SET geometry = ST_BUFFER(geometry, 0)? – J. Monticolo Feb 20 '21 at 16:23ogrinfo natural_earth_vector/packages/natural_earth_vector.sqlite -dialect SQLite -sql "UPDATE a_sqlite_table SET geometry = ST_MakeValid(geometry). – user30184 Feb 20 '21 at 17:06no such function: ST_MakeValid. – swiss_knight Feb 20 '21 at 18:17MakeValid(geometry)? – J. Monticolo Feb 20 '21 at 18:55no such function: MakeValidI'm wondering; would it be possible to fix, at the command line, invalid geometries inside a GeoPackage instead of the db.sqlite? – swiss_knight Feb 20 '21 at 19:02no such function: ST_MakeValid. I also tried without theST_prefix and:no such function: MakeValid. – swiss_knight Feb 21 '21 at 09:59