7

I use the following ogr2ogr command to import my open file geodatabase into PostgreSQL.

# Note, I use the -append because I am adding to preexisting tables with the same structure
ogr2ogr -append -f "PostgreSQL" PG:"dbname=database host=localhost user=username password=password" my.gdb

This works just fine, but it always specifies the geometry field as wkb_geometry, and I'd like it to be geom as is the usual convention. I thought this might be controlled by the -geomfield option, but it seems that this is the not the correct flag (the documentation is too vague for me to be sure though).

If it was just one geodatabase, I could simply loop through and rename all the columns to geom, but since I will be appending multiple databases together that won't work.

tinlyx
11.3k18 gold badges78 silver badges130 bronze badges
asked Sep 2, 2017 at 21:47
3
  • Please do not ask multiple questions. Commented Sep 2, 2017 at 22:08
  • Note, I use the -append because I am adding to preexisting tables with the same structure what is the field called in the table that you're appending too. Commented Sep 2, 2017 at 23:46
  • @EvanCaroll Actually what I first do is upload First.gdb without the -append then add the others. So the geom field in the tables is wkb_geometry by default. Commented Sep 3, 2017 at 20:21

1 Answer 1

15

In the help in ogr2ogr --long-usage, there is layer creation option:

-lco NAME=VALUE: Layer creation option (format specific)

You can use the driver specific option GEOMETRY_NAME=geom to

Set name of geometry column in new table

as follows:

ogr2ogr -lco GEOMETRY_NAME=geom -append -f "PostgreSQL" PG:"dbname=database host=localhost user=username password=password" my.gdb

See related question How to let ogr/gdal CreateLayer() create a `geom` field instead of `wkb_geometry`?.

answered Sep 3, 2017 at 0:35
2
  • This works, however, I am having trouble adding the laundered option to -lco. Is there some trick to passing multiple parameters to -lco? ogr2ogr -lco GEOMETRY_NAME=geom LAUNDER=NO -f "PostgreSQL" PG:"dbname=database schemas=schema" my.gdb Commented Sep 5, 2017 at 16:43
  • 2
    Got it, turns out you need to specify -lco before each individual option. Commented Sep 5, 2017 at 16:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.