3

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.

  • Please do not ask multiple questions. – Vince Sep 2 '17 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. – Evan Carroll Sep 2 '17 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. – Andy Sep 3 '17 at 20:21
9

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`?.

  • 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 – Andy Sep 5 '17 at 16:43
  • 1
    Got it, turns out you need to specify -lco before each individual option. – Andy Sep 5 '17 at 16:55

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.