在 Python 脚本中使用地理处理任务
可在脚本中使用 ArcGIS Server 地理处理任务。基本步骤如下
- 以工具箱的形式添加服务。
- 由于许多任务使用要素集和记录集,可以通过查询任务获取要素集方案或记录集方案。
- 加载要素或记录。
- 启动工具的执行。
- 查询工具执行的结果并等待查询完成。
- 查询结果以获取输出。
脚本示例:
import arcpy, time
# Add a geoprocessing service as a toolbox
# Syntax: ArcGIS Server link;ToolBoxName with the Tool name is the next attribute
#
arcpy.ImportToolbox("http://degrassi/arcgis/services;BufferToolBox","Buffer")
# One of the tasks is BufferPoints and its first parameter is a feature
# set. Get the feature set from the task.
#
inFeatSet = arcpy.GetParameterValue("Buffer", 0)
# Load an existing feature class into the feature set
#
inFeatSet.load("C:/datasets/aoi/observations.shp")
# Start execution of the task
# Service is executed by the toolName_aliasName
#
result = arcpy.Buffer_Buffer(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:/mydata/gpResults.gbd/output1")
其他主题:
|
主题 |
描述 |
|---|---|
|
关于如何在脚本中添加工具箱和地理处理服务的详细信息 | |
|
关于创建、加载和保存要素集数据与记录集数据的详细信息 | |
|
关于查询工具结果或任务结果的详细信息 | |
|
结果类属性和方法的详细信息 |
相关主题
7/10/2012