ArcGIS Server Banner

Using geoprocessing tasks in Python scripts

Using geoprocessing tasks in Python scripts

Release 9.3 E-mail This TopicPrintable VersionGive Us feedback
Note: This topic was updated for 9.3.1.

You can use geoprocessing tasks in scripts. The basic steps are the following:

An example script is below. For more detailed information, consult the table of topics that follows the example script.


import arcgisscripting
gp = arcgisscripting.create(9.3)

# Add a geoprocessing service as a toolbox
#
gp.AddToolbox("http://flame7/arcgis/services;BufferService")

# One of the tasks is BufferPoints and its first parameter is a feature
#  set. Get the feature set from the task.
#
inFeatSet= gp.GetParameterValue("BufferPoints", 0)

# Load an existing feature class into the feature set
#
inFeatSet.Load("c:/temp/base.gdb/towers")

# Start execution of the task
#
result = gp.BufferPoints(inFeatSet, "500 feet")

# Query the result object to detect when the service has finished execution
#
while result.Status < 4:
    time.sleep(0.2)

# The output of this task is a feature set of the buffered points. Get the output
#   by index and save to a geodatabase feature class.
#
outFeatSet = result.GetOutput(0)
outFeatSet.Save("c:/temp/base.gdb/towers_buffer")


Topic Description
Adding and removing toolboxes Details on how to add toolboxes and (geoprocessing services) within a script
FeatureSets and RecordSets Details about creating, loading, and saving feature set and record set data
Getting results from a geoprocessing tool Details about querying the result of a tool or task
Result object Details of result object properties and methods