Result (arcpy)

摘要

通过地理处理工具返回 Result 对象。

讨论

结果对象的优点是可以保留工具执行的相关信息,包括消息、参数和输出。即使在运行了多个其他工具后仍可保留这些结果。

语法

Result (toolname, resultID)
参数说明数据类型
toolname

The name of the executed tool.

String
resultID

The job ID.

Integer

属性

属性说明数据类型
inputCount
(只读)

Returns the number of inputs.

Integer
maxSeverity
(只读)

Returns the maximum severity of the messages.

  • 0If the tool produced only informative messages.
  • 1 If the tool produced a warning message, but no error messages.
  • 2 If the tool produced an error message.
Integer
messageCount
(只读)

Returns the number of messages.

Integer
outputCount
(只读)

Returns the number of outputs.

Integer
resultID
(只读)

Gets the job ID. If the tool is not a geoprocessing service, the resultID will be "".

String
status
(只读)

Gets the job status.

  • 0New
  • 1Submitted
  • 2Waiting
  • 3Executing
  • 4Succeeded
  • 5Failed
  • 6Timed out
  • 7Cancelling
  • 8Cancelled
  • 9Deleting
  • 10Deleted
Integer

方法概述

方法说明
cancel ()

Cancels an associated job

getInput (index)

Returns a given input, either as a recordset or string.

getMapImageURL ({parameter_list}, {height}, {width}, {resolution})

Gets a map service image for a given output, if one exists.

getMessage (index)

Returns a specific message.

getMessages ({severity})

Returns messages.

getOutput (index)

以记录集或者字符串形式返回给定的输出。

如果工具(如 MakeFeatureLayer)的输出是一个图层,则 getOutput 将返回 Layer 对象。

getSeverity (index)

Returns the severity of a specific message.

saveToFile (rlt_file)

将结果保存至结果文件 (.rlt)

方法

cancel ()
getInput (index)
参数说明数据类型
index

The index position of the input.

Integer
返回值
数据类型说明
Object

The input, either as a recordset or string.

getMapImageURL ({parameter_list}, {height}, {width}, {resolution})
参数说明数据类型
parameter_list

Parameter(s) on which the map service image will be based.

Integer
height

The height of the image.

Double
width

The width of the image.

Double
resolution

The resolution of the image.

Double
返回值
数据类型说明
String

The URL of the map image.

getMessage (index)
参数说明数据类型
index

The index position of the message.

Integer
返回值
数据类型说明
String

The geoprocessing message.

getMessages ({severity})
参数说明数据类型
severity

The type of messages to be returned: 0=message, 1=warning, 2=error. Not specifying a value returns all message types.

  • 0informational message
  • 1warning message
  • 2error message

(默认值为 0)

Integer
返回值
数据类型说明
String

The geoprocessing messages.

getOutput (index)
参数说明数据类型
index

The index position of the outputs.

Integer
返回值
数据类型说明
Object

输出为记录集或者字符串形式。

如果工具(如 MakeFeatureLayer)的输出是一个图层,则 getOutput 将返回 Layer 对象。

还可按索引访问结果输出,因此 result.getOutput(0)result[0] 是等效的。

getSeverity (index)
参数说明数据类型
index

The message index position.

Integer
返回值
数据类型说明
Integer

The severity of the specific message.

  • 0informational message
  • 1warning message
  • 2error message
saveToFile (rlt_file)
参数说明数据类型
rlt_file

Full path to the output result file (.rlt).

String

代码实例

Result 示例 1

使用从 GetCount 返回的结果对象来确定表计数。

import arcpy

in_table = arcpy.GetParameterAsText(0)
result = arcpy.GetCount_management(in_table)
print result[0]
Result 示例 2

从服务器工具获取要素集方案、将数据加载至要素集,将要素集传递到服务器工具并检查结果对象。完成后,将结果保存到本地数据集。

import time
import arcpy

# Add a toolbox from a server
arcpy.ImportToolbox("http://myserver/arcgis/services;GP/BufferByVal",
                    "servertools")

# Use GetParameterValue to get a featureset object with the default
# schema of the first parameter of the tool 'bufferpoints'
in_featureset = arcpy.GetParameterValue("bufferpoints", 0)

# Load a shapefile into the featureset
in_featureset.load("C:/Data/roads.shp")

# Run a server tool named BufferPoints with featureset created above
result = arcpy.BufferPoints_server(in_featureset, "500 feet")

# Check the status of the result object every 0.2 seconds
#    until it has a value of 4 (succeeded) or greater
while result.status < 4:
    time.sleep(0.2)

# Get the output FeatureSet back from the server and save to a local geodatabase
out_featureset = result.getOutput(0)
out_featureset.save("c:/temp/base.gdb/roads_buffer")
Result 示例 3

使用工具名称和结果 ID 重新创建原始地理处理服务输出。

import arcpy

# Add the toolbox from the server
arcpy.ImportToolbox("http://myserver/arcgis/services;GP/BufferByVal")

# Recreate the original output using the tool name and result id
result_id = 'jfea96e13ba7b443cb04ba47c19899a1b'
result = arcpy.Result("BufferPoints", result_id)

相关主题

5/10/2014