Convert File GDB to PostGIS Database

HowTo:File GDB Feature to PostGIS Database

The goal of this post is to get our data from a File GDB to a format that GeoServer can use, specifically a PostGIS GDB. If we try and use a shapefile, the field names will be truncated and this will invalidate your schema that you have worked so hard to conform to the USGIN schema standards.

*Only works for 10.x and up geodatabases. You need to upgrade your gdb to 10.x if you are using an older geodatabase.

Overview:

0)Download/Install PostGIS

1)Download/Install GDAL with ESRI File GDB support

2)Convert layers from File GDB to PostGIS GDB with ogr2ogr


0)Download/Install PostGIS

Before you begin, I am assuming that you already have PostGIS installed. If you don’t, the easiest way to install it is with the OpenGeo Suite. That will install GeoServer, PostGIS, and some other GIS open source applicatons. If you just need PostGIS, the easiest way is from http://www.enterprisedb.com/products-services-training/pgdownload . Download and install.

This tutorial will assume that you have downloaded the OpenGeo Suite, but the only thing that will be different is that the default port may be “54321” for OpenGeo instead of “5432” if PostGIS was installed separately. Also, the default username and password will be “admin” and “geoserver” if you are using the OpenGeo Suite.

1)Download/Install GDAL with ESRI File GDB support

Download OSGeo4W Setup http://trac.osgeo.org/osgeo4w/ . Run setup as administrator and choose the Express install.

OSGeo4W Setup

The express install will install several open source packages including GDAL/OGR and QGIS, but it leaves out the file gdb support for GDAL/OGR. After installation, run it again as administrator and choose Advanced installation. Click on “Skip” for gdal-filegdb. This will set the value to the latest version as you see below. Click next and install the file gdb support for GDAL.

Install File GDB support for GDAL

You will want to add the path to OSGeo4W/bin (ex: “C:\OSGeo4W\bin;”) to the Path Environment Variables (Right click Computer > Properties > Advanced system settings > Environment Variables > System Variables > Path). Before you do this, open up the console and type ogr2ogr . If that runs, you probably have a separate version of GDAL installed and you need to remove it or at least remove its reference from the Path variable (I had one installed at “C:\Program Files (x86)\GDAL” and I just removed it from the path).

*If you are unfamiliar with the Path Variable, it just keeps you from having to type the full path of a program so you can type ogr2ogr instead of having to type C:\OSGeo4W\bin\ogr2ogr.exe

2)Convert layers from File GDB to PostGIS GDB with ogr2ogr

Open the command prompt and enter the following code:

ogr2ogr -f "PostgreSQL" PG:"host=localhost port=54321 dbname=geoserver user=postgres password=geoserver" "N:\Geothermal\GIS\DataForIllinois\SAGeology\ArkansasGeology.gdb" "GeologyUnitView"

The format is

ogr2ogr -f "PostgreSQL" PG:"connectionString" "C:\pathToFile\file.gdb" "FeatureClassName"

*To get a list of features in the File GDB, open command line and type ogrInfo C:\PathToFile\file.gdb

That’s it! You now have your data in PostGIS and you can now add it to GeoServer.

GeoServer example of PostGIS Data