I'm migrating some old code from GDAL 2 to GDAL 3. I use ogr2ogr
to import a shapefile into PostGIS like this:
ogr2ogr -f PostgreSQL -nln mwe PG:"host=localhost user=myuser" mwe.shp -overwrite
I've saved a copy of an MWE single feature shapefile here if you'd like to follow along. Plain text would make things easier, but the error only seems to occur when I write data from shapefiles to Postgres.
Expected results - GDAL2
When using gdal2, I can query this data in postgres and see the coordinate precision as expected:
select ST_Y(geom)
from (
select (ST_DumpPoints(wkb_geometry)).geom
from mwe
) pts;
yields:
Full info for 'working' stack:
ubuntu 18.04
postgres 11
postgis 3
GDAL 2.2.3, released 2017/11/20
POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="110" GEOS="3.7.1-CAPI-1.11.1 27a5e771" PROJ="Rel. 4.9.3, 15 August 2016" LIBXML="2.9.4" LIBJSON="0.12
.1" LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)"
Actually results - GDAL3
When I run this using GDAL 3, some vertices have inflated coordinate precision:
Full info for not working GDAL stack:
ubuntu 20.02
postgres 13
postgis 3
GDAL 3.0.4, released 2020/01/28
POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="130" GEOS="3.8.0-CAPI-1.13.1 " PROJ="6.3.1" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)"
ogrinfo coordinate precision
When running ogrinfo
on my MWE shapefile using GDAL 3.0.4, I also see the expected coordinate precision:
ogrinfo -al mwe.shp
INFO: Open of `mwe.shp'
using driver `ESRI Shapefile' successful.
. . .
POLYGON ((21.04237 39.579149,21.038807 39.577435,21.036219 39.576187,21.033495 39.574875,21.03046 39.573414,21.024775 39.570475,21.023056 39.569588,21.017654 39.563602,21.009989 39.563313,21.008549 39.563259,21.001377 39.565672,21.001286 39.565702,21.004169 39.575203,21.006231 39.581999,21.013037 39.583546,21.021423 39.584133,21.039852 39.585428,21.04237 39.579149))
Questions
- I suspect ogr2ogr is the issue because I'm using PostGIS 3 in both cases - is that reasonable?
- I've tried
PG_USE_TEXT YES
andPRECISION=NO
flags in ogr2ogr to no effect - Is there any chance that the higher precision coordinates are what's stored in the shapefile, even though
ogrinfo
with GDAL 3 doesn't report them?
I could certainly truncate / manage this change in PostGIS, but am trying to understand why this happened and if there's a way to get the previous behavior.