2
ogr2ogr -lco GEOMETRY_NAME=geom -f "PostgreSQL" "PG:host=localhost user=postgres dbname=lidar password=postgres" "C:/Users/Rose/Documents/faulty_rasters_test/raster_summary/gdaltindex/1.shp" -lco FID=gid -lco PRECISION=yes -nlt PROMOTE_TO_MULTI -nln lidar.test_dem
ogr2ogr -f "PostgreSQL" "PG:host=localhost user=postgres dbname=lidar password=postgres" "C:/Users/Rose/Documents/faulty_rasters_test/raster_summary/gdaltindex/1.shp" -lco GEOMETRY_NAME=geom -lco FID=gid -lco PRECISION=yes -nlt PROMOTE_TO_MULTI -nln lidar.test_dem

Used above to import shapefile into PostgreSQL database, using python.subprocess() and batch shell. No sterr messages were outputted e.g. Python output

The PostgreSQL table was created but the geom column was incorrect.

The geom column was still the default (wkb_geometry), even though it was specified in command. Using PostgreSQL 11.8, pgAdmin 4.20, Python 3.8 e.g.

PostgreSQL Table ogr2ogr output

How do I change this in this command? Is this possible?

1 Answer 1

2

It does definitely work for me. My steps follow:

GDAL version 3.0.4 PostgreSQL version 12.4 PostGIS version 3.0

I created a new schema "lidar" into an existing db. I concluded that your aim is to write table "test_dem" into schema "lidar" in db "lidar" so I tested the same.

I took your command and modified it a bit

ogr2ogr -lco GEOMETRY_NAME=geom -f "PostgreSQL" "PG:host=localhost user=test dbname=lidar password=testpw" "c:\data\nametest.shp" -lco FID=gid -lco PRECISION=yes -nlt PROMOTE_TO_MULTI -nln lidar.test_dem

Then I executed it without Python and the geometry name in PostGIS is "geom".

New table in PostGIS

I wonder if you have an old table remaining from your previous experiments. If you run the command with Python you may not notice the warning that ogr2ogr sends in such case:

Warning 1: Layer creation options ignored since an existing layer is being appended to.
2
  • Glad it's working for you outside python. I couldn't help but notice, this is exactly the same command as the first example in my question I also outputted standard sterr from the subprocess as above?
    – Rose
    Jun 29, 2020 at 22:15
  • Does it work for you outside Python?
    – user30184
    Jun 30, 2020 at 6:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.