Skip To Content

Geoprocessing tasks

In this topic

Version 3.7

Geoprocessing allows you to automate your geographic information system (GIS) analyses by creating custom tools and linking them within ArcGIS. You can arrange these tools in a logical way to accomplish a multistep task in a single operation rather than a series of manually run tools.

The Geoprocessor class in the ArcGIS API for Flex gives you access to various geoprocessing tasks, which are exposed through services in the ArcGIS REST Services Directory.

To use the geoprocessing services, obtain the following information from the Services Directory:

Obtaining the URL

The Services Directory links to all available services. The following screen shot shows a sample geoprocessing service:

Screen shot of a sample geoprocessing service

From this page, you can see that the geoprocessing service Esri_Elevation_World is located in the Elevation folder and runs on sampleserver1.arcgisonline.com.

The following page appears when you click the Viewshed geoprocessing model:

Screen shot of a sample geoprocessing task

To execute this geoprocessing task, copy and paste the following MXML code into your application:

<esri:Geoprocessor
    id="gp"
    url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/
         Elevation/ESRI_Elevation_World/GPServer/Viewshed"
/>

The equivalent code with ActionScript:

var gp:Geoprocessor = new Geoprocessor
("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/
  Elevation/ESRI_Elevation_World/GPServer/Viewshed");

Supplying the parameters

The parameters in the Services Directory show the required inputs and outputs of the task. In the example above, you need to supply all parameters whose Direction is esriGPParameterDirectionInput and whose Parameter Type is esriGPParameterTypeRequired.

You do not have to supply the output parameters because the output is always returned as an array of ParameterValue. For instance, the input parameters might look like the following:

var params:Object =
{"Input_Observation_Point":featureSet, "Viewshed_Distance":vsDistance };

Running the task

How you run the task depends on whether the geoprocessing task is synchronous or asynchronous:

  • Synchronous execution—The client executes the task and waits for a response before proceeding. The Supported Operations section of the Services Directory displays 'Execute Task' for synchronous tasks.
  • Asynchronous execution—The client submits a job, then verifies that it was successful using a unique job ID. When the task completes, the client can retrieve the results. The Supported Operations section of the Services Directory displays 'Submit Job' for asynchronous tasks.

Running a synchronous task

To run a synchronous task, call Geoprocessor.execute(). Supply the input parameters for the task and optionally include a callback function that tells the application how to handle the results:

gp.execute(params, myFunction);

The results of the task are returned to the callback function as an array of ParameterValue. If messages are enabled, you also get an array of GPMessage objects.

You can loop through each item in the results array and add it to the map as shown in the following code:

private function displayResult(event:GeoprocessorEvent):void
{
    for each ( var myGraphic:Graphic in event.parameterValues[0].value.features )
    {
        myGraphic.symbol = viewshedSimpleFill;
        myGraphicsLayer.add( myGraphic );
    }
}

where viewshedSimpleFill has been defined in MXML as:

<esri:SimpleFillSymbol id="viewshedSimpleFill" color="0xFF0000" alpha="0.5">
    <esri:SimpleLineSymbol color="0x000000" width="1"/>
</esri:SimpleFillSymbol>

Running an asynchronous task

To run an asynchronous task, call Geoprocessor.submitJob(). Supply the input parameters and optionally specify (1) a complete callback function to be called when the job is successful, and (2) a status callback function when the geoprocessor checks the job status:

gp.submitJob(params, MyCompleteCallback, myStatusCallback);

The status callback receives a JobInfo object containing the job ID, the job status, and any GPMessage objects returned by the geoprocessor.