HOW TO

Execute Spatial ETL tools using Python script

Last Published: April 26, 2020

Summary

Spatial ETL tools, created using the Data Interoperability extension, are not typically part of toolboxes in the default ArcToolbox. Thus, Spatial ETL tools are considered as custom-built tools and are not recognized when executed in a Python script. A Python script executes a Spatial ETL tool if the Data Interoperability extension is checked out, the ETL tool is added to a model, and the model is executed using a Python script with the arcpy.ImportToolbox function.

Provided are code samples used to check out the Data Interoperability extension (if available), import the toolbox containing the model and ETL tool, and execute the model.

Procedure



A. Use the sample code for checking out and checking in licenses for extensions.

Use the CheckExtension function to check if a license is available to be checked out for a specific type of extension; use the CheckOutExtension function to retrieve the license. Once the extension license is retrieved by the script, tools requiring that extension can be executed. To return the license and enable other applications to use the license, use the CheckInExtension function.

Code:
## A returned value of Failed, Unavailable, or NotLicensed indicates that the extension could not be successfully checked out

print "Enable Data Interoperability Extension Start"

try:
if arcpy.CheckExtension("DataInteroperability") == "Available":
arcpy.CheckOutExtension("DataInteroperability")
print "Checked out \"DataInteroperability\" Extension"
else:
raise LicenseError
except LicenseError:
print "Data Interoperability license is unavailable"
except:
print arcpy.GetMessages(2)

finally:
# Check in the ArcGIS DataInteroperability extension once the process is completed
arcpy.CheckInExtension("DataInteroperability")
print "Checked in \"DataInteroperability\" Extension"

B. Set necessary variables, import the toolbox containing the Spatial ETL tool and model, and execute the model.

Code:
print "Define Variables"
## The path to the input toolbox. This can be found by right clicking on the toolbox in ArcCatalog, or the Catalog Window in ArcMap, and opening the properties.
## The path to the toolbox should be listed under the Location section.
input_toolbox_path = r"C:\Example\DataInteropToolbox.tbx"

## The input and output data paths.
Source_Google_Earth_KML_File_or_URL_="C:\Example\KML\Counties_LayerToKML.kmz"
Destination_Esri_File_Geodatabase_="C:\Example\OutGeodatabase.gdb"

print "Variables defined, starting process"

## Import custom toolbox (input toolbox path, toolbox alias)
##
## The variable used above (input_toolbox_path) can be used for the input file because it is looking for the location of the toolbox.
## The Toolbox Alias can be found by right clicking on the toolbox in ArcCatalog, or the Catalog Window in ArcMap, and opening the properties.
## The name used for the alias should be listed in the Alias section. If this is blank, specify an alias and apply the changes to enable the alias in the script.

print "Import Toolbox from: " + str(input_toolbox_path)
arcpy.ImportToolbox(input_toolbox_path, "DataInteropToolboxAlias")

print "Executing tool"
try:
## Run the tool in the custom toolbox. The tool is identified by the
## Tool-name _ Toolbox-alias; with the underscore included.
## Model-Name_Toolbox-Alias (the underscore is needed as well)
## arcpy.Model-Name_Toolbox-Alias()
arcpy.KMLToGDBModel_DataInteropToolboxAlias(Source_Google_Earth_KML_File_or_URL_, Destination_Esri_File_Geodatabase_)
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))

Below is a sample script used when checking out the Data Interoperability extension, if available, and executing the model containing the Spatial ETL tool with the arcpy.ImportToolbox function:

Code:
import arcinfo
import arcpy

arcpy.env.overwriteOutput = True
if arcpy.env.overwriteOutput:
print "Overwrite Output is true!"
else:
print "Overwrite Output is false!"

print "Enable Data Interoperability Extension Start"
try:
if arcpy.CheckExtension("DataInteroperability") == "Available":
arcpy.CheckOutExtension("DataInteroperability")
print "Checked out \"DataInteroperability\" Extension"
else:
raise LicenseError
except LicenseError:
print "Data Interoperability license is unavailable"
except:
print arcpy.GetMessages(2)
print "Enabled Data Interoperability Extension End"

print "Define Variables"
Source_Google_Earth_KML_File_or_URL_="C:\Example\KML\Counties_LayerToKML.kmz"
Destination_Esri_File_Geodatabase_="C:\Example\OutGeodatabase.gdb"
print "Variables defined, starting process"

print "Import Toolbox from: " + str(input_toolbox_path)
arcpy.ImportToolbox(input_toolbox_path, "DataInteropToolboxAlias")

print "Executing tool"
try:
arcpy.KMLToGDBModel_DataInteropToolboxAlias(Source_Google_Earth_KML_File_or_URL_, Destination_Esri_File_Geodatabase_)
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
finally:
arcpy.CheckInExtension("DataInteroperability")
print "Checked in \"DataInteroperability\" Extension"

print "Script Completed"

Article ID: 000012387

Software:
  • ArcMap

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options