Tuesday, 16 May 2017

Gdal Python Bindings and File Geodatabase API


I'm trying to get python 2.7 to work with GDAL/OGR and an ESRI file geodatabase. There have been a few similar questions asked but the answers don't fully resolve my situation.


I have installed the 64-bit GDAL Core files from http://www.gisinternals.com/sdk/ I have also installed the Python Bindings and the File GDB.


The background to the problem is that when I run ogrinfo --formats from the command line it returns: "FileGDB" (read/write), when I run ogr from the command line I can see the layers in the Geodatabase BUT when I try to use the following code in Python in returns "None"



driver = gdal.GetDriverByName('FileGDB')
ds = driver.Open(r"my file.gdb",0)
print driver

Ogr definitely works in python because the following code returns the correct response:


driver = ogr.GetDriverByName("ESRI Shapefile")
ds = driver.Open(r"My Shapefile.shp",0)
print ds

driver = gdal.GetDriverByName('GTiff')

ds = driver.Open(r"My GeoTiff.shp",0)
print driver

Does anybody have any pointers to resolve this.


Thanks



Answer



I found the solution to this was to add GDAL_DRIVER_PATH = C:\Program Files\GDAL\gdalplugins in the Environment Variables.


This was in addition to Mike Toews comment about the correct usage being ogr.GetDriverByName('FileGDB')


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...