Synthèse
The result of a geoprocessing tool.
Discussion
A Result object maintains information about a tool operation after it has completed. This includes messages, parameters, and outputs. Functions such as arcpy.GetMessages provide information solely from the preceding tool. However, you can maintain a Result object even after running other tools.
Syntaxe
Result (toolname, resultID)
Paramètre | Explication | Type de données |
toolname | The name of the executed tool. | String |
resultID | The job ID. | Integer |
Propriétés
Propriété | Explication | Type de données |
inputCount (Lecture seule) | Returns the number of inputs. | Integer |
maxSeverity (Lecture seule) | Returns the maximum severity of the messages.
| Integer |
messageCount (Lecture seule) | Returns the number of messages. | Integer |
outputCount (Lecture seule) | Returns the number of outputs. | Integer |
resultID (Lecture seule) | Gets the job ID. If the tool is not a geoprocessing service, the resultID will be "". | String |
status (Lecture seule) | Gets the job status.
| Integer |
Vue d’ensemble des méthodes
Méthode | Explication |
cancel () | Cancels an associated job |
getAllMessages () | Returns the message types, return codes, and message strings. |
getInput (index) | Returns a given input, either as a string or a RecordSet object. |
getMapImageURL ({parameter_list}, {height}, {width}, {resolution}) | Returns a map service image for a given output, if one exists. |
getMessage (index) | Returns a specific message by index position. |
getMessages ({severity}) | Returns the geoprocessing tool messages. |
getOutput (index) | Returns a given output, either as a RecordSet object or a string. If the output of the tool, such as Make Feature Layer, is a layer, getOutput will return a Layer object. |
getSeverity (index) | Returns the severity of a specific message. |
saveToFile (rlt_file) | Saves the result to a result file. Remarque :saveToFile is not supported in ArcGIS Pro; use the Package Result tool instead. |
Méthodes
cancel ()
getAllMessages ()
Type de données | Explication |
List | Returns a list of lists that includes by position: the type, return code, and message string. The first item in each internal list is an integer representing the message type.
The second item is an integer representing the message return code. If the message has an associated ID number, the item will be ID number. Error messages that do not have an ID will return -2147467259. All other messages will return a 0. The second item is the message string. |
getInput (index)
Paramètre | Explication | Type de données |
index | The index position of the input as an integer, or the parameter name. | Variant |
Type de données | Explication |
Variant | The input, either as a RecordSet object or a string. |
getMapImageURL ({parameter_list}, {height}, {width}, {resolution})
Paramètre | Explication | Type de données |
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 |
Type de données | Explication |
String | The URL of the map image. |
getMessage (index)
Paramètre | Explication | Type de données |
index | The index position of the message. | Integer |
Type de données | Explication |
String | The geoprocessing message. |
getMessages ({severity})
Paramètre | Explication | Type de données |
severity | The type of messages to be returned.
Not specifying a severity level will return all types of messages. (La valeur par défaut est 0) | Integer |
Type de données | Explication |
String | The geoprocessing tool messages. |
getOutput (index)
Paramètre | Explication | Type de données |
index | The index position of the output as an integer, or the parameter name. | Variant |
Type de données | Explication |
Variant | The output, either as a RecordSet or a string. If the output of the tool, such as Make Feature Layer, is a layer, getOutput will return a Layer object. Result outputs can also be accessed by index by integer or by name. For example, to access the record count from the Get Count tool, result.getOutput(0), result[0], result.getOutput("row_count"), and result["row_count"] are equivalent. |
getSeverity (index)
Paramètre | Explication | Type de données |
index | The message index position. | Integer |
Type de données | Explication |
Integer | The severity of the specific message.
|
saveToFile (rlt_file)
Paramètre | Explication | Type de données |
rlt_file | Full path to the output result file (.rlt). | String |
Exemple de code
From a Result object returned from the Get Count tool, access the record count by index.
import arcpy
in_table = arcpy.GetParameterAsText(0)
result = arcpy.management.GetCount(in_table)
print(result[0])
From a Result object returned from the Get Count tool, access the record count by name.
import arcpy
in_table = arcpy.GetParameterAsText(0)
result = arcpy.management.GetCount(in_table)
print(result["row_count"])
The script obtains the feature set schema from a server tool, then loads data to the feature set, and passes it to the server tool. Once the tool completes, the script saves the result to a local dataset.
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")
Re-create the output of a geoprocessing service using the tool name and result 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)
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?