Importing GDB files into a PostgreSQL database - hackoregon/disaster-resilience GitHub Wiki

Question Is there a simple, automated way to import GDB files into a PostgreSQL database?

Introduction During the Disaster Resilience project we will get a number of database extracts. To cohesively manage these extracts in development and production will will probably want to load them into a database.

About GDB files GDB files are ESRI geo-spatial data extracted from a database to a file.

We have some assumed tools. These are open source.

  • PostgreSQL (version 9.5?)
  • QGIS Desktop with GRASS

I used a utility that is installed with QGIS called OGR2OGR. OGR2OGR is designed to convert simple features data between file formats. It works to import the GDB files into PostgreSQL 9.5. Reference: http://www.gdal.org/ogr2ogr.html

By default, OGR2OGR does not come with the PostgreSQL driver, so it must be installed. Here is how to install that driver:

Need to Install GDAL with OSGeo4W or from gisinternals.com and you should get PostGIS driver. https://gis.stackexchange.com/questions/229319/unable-find-driver-postgresql-in-ogr2ogr

To do this, run the OSGeo4W setup program:

  • C:\Program Files\QGIS 2.14\bin\osgeo4w-setup.exe
  • Choose Advanced Install [Next]
  • Install from Internet [Next]
  • All users [Next]
  • Select the GDAL packages gdaldrivers

Once the PostgreSQL driver is installed, you can run the import.

  1. Open a OSGeo4W Shell
  2. Change to the directory where you have your GDB files eg: cd \develop\hackoregon\disaster On my computer I have a subdirectory off this called water utilities_gdb It contains Utilities_Water.gdb
  3. Make sure Postgres database service is running
  4. run this command to import the water utilities ogr2ogr.exe -overwrite -f "PostgreSQL" PG:"host=localhost port=5432 dbname=<dbname> user=<username> password=<password>" "water utilities_gdb\Utilities_Water.gdb" -progress
  5. Do the same for the ORP data ogr2ogr.exe -overwrite -f "PostgreSQL" PG:"host=localhost port=5432 dbname=<dbname> user=<username> password=<password>" "O-13-06\Oregon_Resilience_Plan_Ground_Motion_and_Ground_Failure_Maps.gdb" -progress

For this case

<dbname>=foo
<username>=postgres

⚠️ **GitHub.com Fallback** ⚠️