Thursday, April 11, 2013

Running GDAL and arcpy together (ArcGIS 10.1, GDAL 1.9.2, python 2.7.4)

There are many use cases for running GDAL and arcpy in the same python instance.  GDAL is the most popular open source geopspatial geoprocessing toolset and arcpy is Esri's python wrapper for the entire ArcGIS geoprocessing toolset.

However, doing so can get quite tricky.  GDAL's python bindings are not easily configured for Windows (and ArcGIS/ArcObjects is Windows-only).  The OSGeo4W project can be used to do so, but the bundled Python does not play well with arcpy.  arcpy itself depends on numpy and requires multiple path inclusions.

Here are steps I took to import gdal and arcpy.  
I tested by successfully running arcpy.RasterToNetCDF_md()  (though I haven't tested gdal yet).

Step 1: Install standalone python to C:\Python274 (download from
Step 2: Add numpy (version bundled with ArcGIS) and Desktop10.1.pth to C:\Python274\Lib\site-packages (download from
Step 3: Install GDAL binaries and python bindings (download installer from
Step 4: Run import commands "import arcpy" and "from osgeo import gdal"

Some considerations:
arcpy is 32-bit (since it wraps arcobjects), so 32-bit python (etc.) are necessary
all versions of wrappers must be compatible with the same Python interpreter

1 comment:

Evan Heisman said...
This comment has been removed by the author.