Result
汇总
地理处理工具的结果。
讨论
运行完成后, Result 对象将保留有关工具操作的信息。 其中包括消息、参数和输出。 arcpy.GetMessages 等函数仅提供来自前面工具的信息。 但即使在运行其他工具后,您仍可保留 Result 对象。
语法
Result(toolname, resultID)
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
toolname |
The name of the tool that was run. |
String |
|
resultID |
The job ID. |
Integer |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
inputCount (只读) |
输入数量。 |
Integer |
|
maxSeverity (只读) |
指定消息的最大严重性。
|
Integer |
|
messageCount (只读) |
消息数量。 |
Integer |
|
outputCount (只读) |
输出数量。 |
Integer |
|
resultID (只读) |
作业 ID。 如果工具不是地理处理服务,则值将为 |
String |
|
status (只读) |
指定作业状态。
|
Integer |
方法
cancel()
取消关联作业。
getAllMessages()
返回消息类型、返回代码和消息字符串。
返回值
| 数据类型 | 说明 |
|---|---|
|
List |
返回按位置包含的列表的列表:类型、返回代码和消息字符串。 每个内部列表中的第一个项目是表示消息类型的整数。
第一个项目是表示消息返回代码的整数。 如果消息具有关联的 ID 编号,则该项目将为 ID 编号。 没有 ID 的错误消息将返回 -2147467259。所有其他消息将返回 0。 第二个项目为消息字符串。 |
getCharts({wildcard})
返回由工具创建的 chart 对象。
| 名称 | 说明 | 数据类型 | ||||||
|---|---|---|---|---|---|---|---|---|
|
wildcard (可选) |
Limits the charts returned by title. If no value is specified, all charts are returned. The wildcard is not case sensitive.
|
* |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
图表对象的列表。 对象的类型将根据图表的类型而有所不同,例如 |
getInput(index)
以字符串或 RecordSet 对象的形式返回给定的输入。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
index |
The index position of the input as an integer, or the parameter name. |
Variant |
返回值
| 数据类型 | 说明 |
|---|---|
|
Variant |
作为 |
getMapImageURL({parameter_list}, {height}, {width}, {resolution})
返回给定输出的地图服务影像(如果存在)。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
parameter_list (可选) |
The parameters 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 |
地图影像的 URL。 |
getMessage(index)
按索引位置返回特定消息。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
index |
The index position of the message. |
Integer |
返回值
| 数据类型 | 说明 |
|---|---|
|
String |
地理处理消息。 |
getMessages({severity})
返回地理处理工具消息。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
severity (可选) |
The type of messages to be returned.
Not specifying a severity level will return all types of messages. (默认值为 0) |
Integer |
返回值
| 数据类型 | 说明 |
|---|---|
|
String |
地理处理工具消息。 |
getOutput(index)
以 RecordSet 对象或字符串形式返回给定的输出。
如果工具(如 创建要素图层 )的输出是一个图层,则 getOutput 将返回 Layer 对象。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
index |
The index position of the output as an integer, or the parameter name. |
Variant |
返回值
| 数据类型 | 说明 |
|---|---|
|
Variant |
输出为 如果工具(如 创建要素图层 )的输出是一个图层,则 还可以通过整型索引或名称访问结果输出。 例如,要从 获取计数 工具访问记录计数, |
getSeverity(index)
指定特定消息的严重性。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
index |
The message index position. |
Integer |
返回值
| 数据类型 | 说明 |
|---|---|
|
Integer |
特定消息的严重性。
|
saveToFile(rlt_file)
将结果保存至结果文件。
注:
不支持在 ArcGIS Pro 中使用
saveToFile;可使用 打包结果 工具代替。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
rlt_file |
The full path to the output result file ( |
String |
代码示例
从 获取计数 工具返回的 Result 对象,按索引访问记录计数。
import arcpy
in_table = arcpy.GetParameterAsText(0)
result = arcpy.management.GetCount(in_table)
print(result[0])
从 获取计数 工具返回的 Result 对象,按名称访问记录计数。
import arcpy
in_table = arcpy.GetParameterAsText(0)
result = arcpy.management.GetCount(in_table)
print(result["row_count"])
该脚本从服务器工具获取要素集架构,然后将数据加载到要素集,并将其传递给服务器工具。 工具运行完成后,脚本会将结果保存到本地数据集。
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.server.BufferPoints(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")
使用工具名称和结果 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)