[GIS] Error importing shp into postgis using ogr2ogr

ogr2ogrpostgisshapefile

I run an automated script that copies a number shapefiles into PostGIS. I have a problem with one dataset which fails during the export. As the roads.shp dataset is maintained by someone else, I automate making a copy of their shapefile into my PostGIS database. My error is;

ERROR 1: COPY STATEMENT FAILED
ERROR: numeric field overflow
DETAIL: A field with precision 13, scale 11 must round to an absolute value less than 10^2.
CONTEXT: COPY ccbc_roads, line 2, column length :"222.05900000000"

My code is as follows;

ogr2ogr.exe -f PostgreSQL PG:"dbname=postgis host=localhost user=postgres password=mypassword active_schema=ccbc_data" "roads.shp" -overwrite -a_srs "EPSG:27700" -lco GEOMETRY_NAME=geom -nln "ccbc_roads" -nlt PROMOTE_TO_MULTI --config PG_USE_COPY YES

The field that is causing the issue is the road length. Is there a way to change the scale from 11 to 2 in my code so that the script will work?

Best Answer

There is more sustainable way for this which is using -unsetFieldWidth flag. With this setting you won't need to use sql and it applies all layers.

Related Question