A number of organisations use ESRI's ArcMap software to run their Geographic Information System (GIS). Using ArcMap it's possible to create a toolbox that acts as a set of macros to perform operations on the data. I'm not a GIS or Python expert, but I recently had to assist a colleague in automating these updates. This post explains the pitfalls I encountered and how to get a working set of scripts.
Note: To use the DataInteroperability extension you do need an additional license.
It's possible to export the ArcMap toolbox as a Python script and to then run that directly. This seems to work on Windows Server 2008 R2 but not on newer operating systems such as Server 2012 R2. I spent a reasonable amount of time trying to work out why and wasn't able to determine what was going wrong beyond observing the environment was different. ESRI support advised the better way was to schedule a model builder so that's the approach we started to look at.
The first issue I encountered was the ESRI documentation could have been clearer. After much tinkering and research I managed to determine when they were saying a method was called
modelName() they actually meant you had to substitute the name of the model! A simple note to that affect on the page would have saved about 45 minutes (I was having to learn how to use Python at the same time).
Eventually we were successful in getting model builder working via the toolbox for data that was held on disk. The problem seemed to be around using the data interoperability extension. No matter how I phrased my Google search terms ("Arcpy model with data interop source", "Arcpy model data interoperability source", " ERROR 000732: Community_Assets Polygon: Dataset Interoperability" ) I wasn't finding anything to help.
The error I was receiving implied I wasn't giving the model the type of input it required:
Traceback (most recent call last): File "Jonathan2.py", line 10, in arcpy.Land.ScheduledLandCharges("Interoperability Connections/ScheduledConversionLandCharges.fdl/Community_Assets Polygon'","Q:\Shp_Files\Land_Charges") File "G:\data\Toolbox\ScheduledLandChargesConversion.tbx", line 25, in ScheduledLandCharges arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Assets_of_Community_Value Polygon: Dataset Interoperability Connections/ScheduledConversionLandCharges.fdl/Community_Assets Polygon' does not exist or is not supported The value does not exist. ERROR 000732: Input Features: Dataset 'Interoperability Connections/ScheduledConversionLandCharges.fdl/Community_Assets Polygon'' does not exist or is not supported Failed to execute (ScheduledLandCharges).
Over to Stack Exchange I went in the hope someone would be able to assist. I posted my question (Unable to use a Toolbox with a input from DataInteroperability) and got an answer within a day or so: the Data Interoperability connection is a file on disk, so I needed to reference that file and not a virtual path like the toolbox did.
First we have to import the
before we then check out the DataInteroperability extension:
if arcpy.CheckExtension("DataInteroperability") == "Available": arcpy.CheckOutExtension("DataInteroperability") print "Checked out \"DataInteroperability\" Extension" else: print "Data Interoperability license is unavailable"
Next we need to import our Toolbox. Make sure you save the toolbox to a location on the server and note the path to the
.tbx file, then import it by referencing its path. Note that a backslash (\) is a special character in Python so you either need to escape it (amusingly with another backslash, \\) or use forward slashes instead (even on Windows). The syntax is:
arcpy.ImportToolbox("path to TBX file",alias)
(You must not include an underscore, _, in your alias.)
As an example:
Next we have to call the model, for which the syntax is:
To find the name of the model either call
help on the toolbox alias (e.g.
help(arcpy.Land)) or check in ArcCatalog:
What if the model needs input / parameters?
Some models need additional parameters in when they're called. We can check if that's the case by looking at the model properties:
- Expand the toolbox in ArcCatalog
- Right click the model (e.g. ScheduledLandCharges in the picture above) and choose properties
- Switch to the parameters tab
We have to provide input for anything listed as required (see below). The data type is also indicated.
Specifying a DataOperability connection as a parameter
This is the stage where I came unstuck, as I tried to provide the virtual path like the toolbox's exported Python would. Instead you have to reference the connection's file on disk, followed by the desired layer name. Connections are stored at
"C:\Users\USERNAME\AppData\Roaming\Safe Software\Interoperability\CONNECTION-NAME.fdl", for example
"C:\Users\gis\AppData\Roaming\Safe Software\Interoperability\ScheduledConversionLandCharges.fdl". Switching to use forward slashes, and adding the name of the layer (`
Assets_of_Community_Value Polygon`) we get
"C:/Users/gis/AppData/Roaming/Safe Software/Interoperability\ScheduledConversionLandCharges.fdl/Assets_of_Community_Value Polygon".
Example Python script
import arcpy if arcpy.CheckExtension("DataInteroperability") == "Available": arcpy.CheckOutExtension("DataInteroperability") print "Checked out \"DataInteroperability\" Extension" else: print "Data Interoperability license is unavailable" arcpy.ImportToolbox("G:/data/Toolbox/ScheduledLandChargesConversion.tbx","Land") arcpy.Land.ScheduledLandCharges("C:/Users/gis/AppData/Roaming/Safe Software/Interoperability\ScheduledConversionLandCharges.fdl/Assets_of_Community_Value Polygon","Q:/Shp_Files/Land_Charges")
- When using Arcpy, toolboxes and models with a DataInteroperability data source, make sure you reference the connection's
FDLfile in your Python script.
- DataIneroperability requires an additional licence
- Use forward slashes ( / ) not back slashes ( \ ) in Python when writing paths
- Ensure any drives that are mentioned in the DataInteroperability connection are available. You can open the
FDLfile in notepad to confirm what paths it accesses.