There are a number of existing Questions that hint at a possible Answer to this Question, but none seem to be providing me with the solution to my problem:
- How to access feature classes in file geodatabases with Python and GDAL?
- How to add GDAL to existing Python installation?
- Gdal Python Bindings and File Geodatabase API
To get GDAL/OGR 1.10 working on a Windows 7 SP1 (64bit) laptop with Python 2.7.3 from ArcGIS 10.2 for Desktop I did the following steps:
- Installed ArcGIS 10.2 for Desktop which installed Python 2.7.3 - there are no other versions of Python present
- Downloaded and installed
gdal-110-1600-x64-core.msi
(compiled 2/6/2014 6:11 AM) from http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1600-x64-gdal-mapserver - Downloaded and installed
gdal-110-1600-x64-filegdb.msi
(compiled 2/6/2014 6:17 AM) from http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1600-x64-gdal-mapserver. As expected this placed anogr_FileGDB.dll
in C:\Program Files\GDAL\gdalplugins. - Added a new system environment variable called
GDAL_DRIVER_PATH
and set it to C:\Program Files\GDAL\gdalplugins, and I appended (using ';') the same folder onto the end of myPath
variable. This was from advice offered in one of the Questions cited above. - Downloaded and installed
GDAL-1.10.1.win32-py2.7.exe
from http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
This enabled me to run some Python scripts from IDLE like the one below to count the number of features in a shapefile.
import os
from osgeo import ogr
daShapefile = r"C:\temp\test.shp"
driver = ogr.GetDriverByName('ESRI Shapefile')
dataSource = driver.Open(daShapefile, 0) # 0 means read-only. 1 means writeable.
# Check to see if shapefile is found.
if dataSource is None:
print 'Could not open %s' % (daShapefile)
else:
print 'Opened %s' % (daShapefile)
layer = dataSource.GetLayer()
featureCount = layer.GetFeatureCount()
print "Number of features in %s: %d" % (os.path.basename(daShapefile),featureCount)
However, when I tried to run the code below:
import os
from osgeo import ogr
daFileGeodatabaseFC = r"C:\temp\test.gdb\testFC"
daFileGeodatabase = r"C:\temp\test.gdb"
featClass = "testFC"
driver = ogr.GetDriverByName('FileGDB')
dataSource = driver.Open(daFileGeodatabase, 0) # 0 means read-only. 1 means writeable.
# Check to see if feature class is found.
if dataSource is None:
print 'Could not open %s' % (daFileGeodatabase)
else:
print 'Opened %s' % (daFileGeodatabase)
layer = dataSource.GetLayer(featClass)
featureCount = layer.GetFeatureCount()
print "Number of features in %s: %d" % (os.path.basename(daFileGeodatabaseFC),featureCount)
I got an error:
Traceback (most recent call last): File "C:\temp\GetFileGDBFeatureCount.py", line 17, in dataSource = driver.Open(daFileGeodatabase, 0) # 0 means read-only. 1 means writeable. AttributeError: 'NoneType' object has no attribute 'Open'
After some more reading I decided to use ogrinfo --formats
in a DOS window to see if FileGDB was recognized and it is!
Am I missing a step or two that would complete enabling OGR FileGDB support for my GDAL/Python/ArcGIS configuration?
I do not class myself as a developer so compiling a new version of GDAL, or starting from scratch and installing OSGeo4W instead are options I would prefer to avoid, if at all possible.