5

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:

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:

  1. Installed ArcGIS 10.2 for Desktop which installed Python 2.7.3 - there are no other versions of Python present
  2. 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
  3. 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 an ogr_FileGDB.dll in C:\Program Files\GDAL\gdalplugins.
  4. 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 my Path variable. This was from advice offered in one of the Questions cited above.
  5. 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!

enter image description here

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.

1 Answer 1

5

These are a few things I noticed, your Python 2.7.3, installed with ArcGIS, is 32 bit while the filegdb plugin is 64 bit. You may need a 64 bit Python to match the filegdb driver. Also, you installed two versions of GDAL 32 bit & 64 bit, this might be ok. When you import osgeo, which version are you importing, 32 or 64? Your GDAL_DRIVER_PATH points to the 64 bit install, looks good.

1
  • +1 I suspect that you are right and am now trying to standardize these parts of my configuration on 32bit to match the Python installed with ArcGIS but if I get no further then I will install Background Geoprocessing to to try and standardize on 64bit instead.
    – PolyGeo
    Feb 8, 2014 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.