Python and Cube
December 19th, 2010One of the advantages of the ESRI ArcGIS Framework is that you can write Python scripts that do GIS things and run them from Cube. Â Even better, Cube uses the Geodatabase format, so you can store and retrieve things from there.
The first thing that is needed is a python script. Â The below is an example that we’re not using at the moment, but it merges multiple transit line files together.
import arcgisscripting, sys, os
gp=arcgisscripting.create()
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolBox/Toolboxes/Data Management Tools.tbx")
print sys.argv
input1=sys.argv[1]
input2=sys.argv[2]
output=sys.argv[3]
in1=input1+input1[input1.rfind("\\"):]+"_PTLine"
in2=input2+input2[input2.rfind("\\"):]+"_PTLine"
input=in1+';'+in2
input=input.replace("\\","/")
output=output.replace("\\","/")
print input
print output
if gp.Exists(output):
gp.delete_management(output)
#input=input1+"_PTLine" +';'+input2 +"_PTLine"
gp.Merge_management(input,output)
print gp.GetMessage
del gp
To call this, we add the following in a Pilot script:
*merge.py {CATALOG_DIR}\Inputs\Transit.mdb\Routes1 {CATALOG_DIR}\Inputs\Transit.mdb\Routes2 {CATALOG_DIR}\Inputs\Transit.mdb\RoutesCombined
This makes it easy to create geoprocessing steps in ArcMap, export them to Python, and call them from the model.