3

I have figured out (through the use of this thread) on how to go from a file GDB to posgreSQL using ogr2ogr. Now what I want to do is import all the feauture classes but change the geometry column to geom.

ogr2ogr -f "PostgreSQL" PG:"host=localhost port=5432 dbname=freelance user=postgres" C:\pathto\oakland.gdb -overwrite -progress

when i run this cmd ogr2ogr command it correctly imports the feature classes into postgresql but the geometry column annoyingly gets renamed to wkb_geometry. I believe there is a way to alter a column for an individual layer but how do you do it for all feature classes?

although I know its recommended to ask this in a new question but if I wanted to project/transform to another SRID while importing into PostgreSQL how would I accomplish this

2

You need to add a Layer Creation Option to your string. The proper one is the following:
-lco geometry_name=geom
You can change "geom" to be whatever you wish your column name to be.

Here is your string with the option added:

ogr2ogr -overwrite -progress -f "PostgreSQL" PG:"host=localhost port=5432 dbname=freelance user=postgres" C:\pathto\oakland.gdb -lco geometry_name=geom

If you want to change your spatial reference, you will add the following option:
-t_srs EPSG:XXXX where XXXX is your desired spatial reference. Simply add as another option in your string. The following shows it added, using 3500 which is the code for NAD 83(NSRS 2007) / US State Plane Coord Sys - California Zone 6 (ftus).

ogr2ogr -overwrite -progress -t_srs EPSG:3500 -f "PostgreSQL" PG:"host=localhost port=5432 dbname=freelance user=postgres" C:\pathto\oakland.gdb -lco geometry_name=geom  

You will need to ensure you have the proper EPSG number for your desired spatial reference. Those can be found at spatialreference.org
For future reference, here is documentation for the ogr2ogr translater: GDAL - OGR2OGR

  • 2
    Apart from being a good answer, it was really nice seeing someone go from 9991 to 10k rep. Enjoy the admin tools :-) – John Powell Mar 29 '17 at 15:35
  • 2
    awesome, thanks! ogr2ogr is so powerful love it – ziggy Mar 29 '17 at 15:38

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.