About tool return values
Geoprocessing results are generated when a tool is executed. The IGeoProcessorResult2 interface always returns the output values of the tool when it is executed. The return value is an object. Typically, this object is the path to the output dataset produced or updated by the tool, but it can be other value types, such as a number or Boolean. If an output for a tool is a multivalue parameter, the values are returned in a string that consists of multiple strings separated by a semicolon.
Output values are always returned to the program from the geoprocessor. Return values are necessary when a tool has no output dataset—instead, it has an output scalar value, such as an integer or Boolean. Return values are helpful when working with multiuser databases, since output names are qualified with a user's name and table space when outputs are written in the database.
The following code examples show how return values are captured and what their values could be:
[C#] public void SampleGeoprocessingReturnValue_1(Geoprocessor GP, IGPProcess bufferTool)
{
// Example 1: Return path to output data:
// The return value is an object of type string that is the path to the output.
IGeoProcessorResult2 pResult=(IGeoProcessorResult2)GP.Execute(bufferTool, null)
;
object returnval=pResult.ReturnValue;
if ((returnval)is string)
{
// Add your code here.
}
}
[VB.NET] Public Sub SampleGeoprocessingReturnValue_1(ByVal GP As Geoprocessor, ByVal bufferTool As IGPProcess)
' Example 1: Return path to output data:
' The return value is an object of type string that is the path to the output.
Dim pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2=CType(GP.Execute(bufferTool, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)
Dim returnval As Object=pResult.ReturnValue
If TypeOf (returnval) Is String Then
' Add your code here.
End If
End Sub
[C#] public void SampleGeoprocessingReturnValue_2(Geoprocessor GP, IGPProcess
calculateGridIndexTool)
{
// Example 2: Return value:
// The return value is an object of type double.
IGeoProcessorResult2 pResult=(IGeoProcessorResult2)GP.Execute
(calculateGridIndexTool, null);
object defgrid=pResult.ReturnValue;
if ((defgrid)is double)
{
// Add your code here.
}
}
[VB.NET] Public Sub SampleGeoprocessingReturnValue_2(ByVal GP As Geoprocessor, ByVal calculateGridIndexTool As IGPProcess)
' Example 2: Return value:
' The return value is an object of type double.
Dim pResult As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2=CType(GP.Execute(calculateGridIndexTool, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)
Dim defgrid As Object=pResult.ReturnValue
If TypeOf (defgrid) Is Double Then
' Add your code here.
End If
End Sub
See Also:
How to run a geoprocessing toolHow to work with result objects
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
- ESRI.ArcGIS.Geoprocessing
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)