I am trying to access a vector dataset in a ESRI File Geodatabase using Python + GDAL. I have successfully compiled GDAL with the file geodatabase API. The FileGDB driver is working correctly since entering

ogrinfo --formats

shows the FileGDB driver and entering

ogrinfo myfilegdb.gdb 

gives me the correct information on the content of the database.

However, I can't find out how to access the content itself in Python. For accessing a shapefile, I would write:

driver = ogr.GetDriverByName('ESRI Shapefile')
ds = driver.Open('shapefile.shp', 0)

When accessing a FileGDB feature class I would assume using the commands:

driver = ogr.GetDriverByName('FileGDB')
ds = driver.Open('myfilegdb.gdb/feature_class', 0)

but this doesn't seem to work since it can not identify/locate the data set. Does anyone know how to call individual feature classes from a ESRI FileGDB.

I'm using Python 2.7, GDAL 1.9.1, filegdb api 1.2 on Ubuntu 12.04 x64. Thanks for any suggestions!


3 Answers 3


You're almost there. This is on Windows 7, Python 2.6.5 32bit, and GDAL 1.9.0:

>>> from osgeo import ogr
>>> driver = ogr.GetDriverByName("FileGDB")
>>> ds = driver.Open(r"C:\temp\buildings.gdb", 0)
>>> ds
<osgeo.ogr.DataSource; proxy of <Swig Object of type 'OGRDataSourceShadow *' at 0x02BB7038> >
>>> ds.GetLayer("buildings")
<osgeo.ogr.Layer; proxy of <Swig Object of type 'OGRLayerShadow *' at 0x02BB7050> >
>>> b = ds.GetLayer("buildings")
>>> sr = b.GetSpatialRef()
>>> sr
<osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x02BB7080> >
>>> sr.ExportToProj4()
'+proj=utm +zone=15 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs '

Once you open the FGDB, then use GetLayer to get at your featureclass.

  • If you get a 'NoneType' being returned by the driver.open() operation, see Alec's answer
    – Hansang
    Oct 16, 2021 at 5:46

Much simpler and intuitive if you use fiona and geopandas

import fiona 
import geopandas as gpd

# Get all the layers from the .gdb file 
layers = fiona.listlayers(gdb_file)

for layer in layers:
    gdf = gpd.read_file(gdb_file,layer=layer)
    # Do stuff with the gdf

Note: fiona uses gdal and geopandas uses fiona

See also Reading the names of geodatabase file layers in Python

  • 1
    Pre-requisites: pip install "GDAL-3.0.2-cp36-cp36m-win_amd64.whl" #see here lfd.uci.edu/~gohlke/pythonlibs ,pip install wheels ,pip install pipwin ,pipwin install numpy ,pipwin install pandas ,pipwin install shapely ,pipwin install gdal ,pipwin install fiona ,pipwin install pyproj ,pipwin install six ,pipwin install rtree ,pipwin install geopandas , Check python is in your Environment Path ,In the GDAL CPx.y shows the version of your Python for 32-bit system use 32bits , comma means a new line Nov 25, 2019 at 19:18

I would like to add that "FileGDB" is a propriatary driver that might not be included with you GDAL package http://www.gdal.org/drv_filegdb.html. This results in GetDriverByName returning None.

There is also the "OpenFileGDB" driver which is read only and is included by default http://www.gdal.org/drv_openfilegdb.html

>>> from osgeo import ogr
>>> driver = ogr.GetDriverByName("OpenFileGDB")
  • The Accepted answer didn't work for me, until i saw this one...should really be a note on the other one
    – Hansang
    Oct 16, 2021 at 5:45

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.