Geoprocessor

AMD: require(["esri/tasks/Geoprocessor"], (Geoprocessor) => { /* code goes here */ });
ESM: import Geoprocessor from "@arcgis/core/tasks/Geoprocessor";
Class: esri/tasks/Geoprocessor
Inheritance: Geoprocessor Task Accessor
Since: ArcGIS API for JavaScript 4.0
Deprecated since version 4.20. Use geoprocessor instead.

Represents a GP Task resource exposed by the ArcGIS REST API. A GP Task resource represents a single task in a GP service published using the ArcGIS Server and it supports one of the following operations dependent on how the service was set up:

  • execute - for when the execution type is synchronous.
  • submitJob - for when the execution type is asynchronous.

If processExtent is not set then execute and submitJob will format web requests compatiable with ArcGIS version prior to 10.6.1.

See also:

Constructors

new Geoprocessor(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class
Stringmore details

The name of the class.

more detailsAccessor
SpatialReferencemore details

The spatial reference of the output geometries.

more detailsGeoprocessor
Extentmore details

ProcessExtent, if specified, will only process features that overlap this extent.

more detailsGeoprocessor
SpatialReferencemore details

The spatial reference that the model will use to perform geometry operations.

more detailsGeoprocessor
Objectmore details

The options to be used for data requests.

more detailsTask
Booleanmore details

If true, m-values will be included in the results if the features have m-values.

more detailsGeoprocessor
Booleanmore details

If true, z-values will be included in the results if the features have z-values.

more detailsGeoprocessor
Stringmore details

ArcGIS Server Rest API endpoint to the resource that receives the geoprocessing request.

more detailsGeoprocessor

Property Details

declaredClass Stringreadonly inherited
Since: ArcGIS API for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

outSpatialReference SpatialReferenceautocast

The spatial reference of the output geometries. If not specified, the output geometries will be in the spatial reference of the input geometries. If processSpatialReference is specified and outSpatialReference is not specified, the output geometries will be in the spatial reference of the process spatial reference.

Default Value:null
processExtent Extentautocast
Since: ArcGIS API for JavaScript 4.13

ProcessExtent, if specified, will only process features that overlap this extent.

Default Value:null
processSpatialReference SpatialReferenceautocast

The spatial reference that the model will use to perform geometry operations. If processSpatialReference is specified and outputSpatialReference is not specified, the output geometries will be in the spatial reference of the process spatial reference.

A possible common scenario for using processSpatialReference and outputSpatialReference is that you would like to perform spatial operations like buffer or clip on a projected coordinate system such as web mercator. And you would like to recieve the output based on a geographic coordinates such as WGS84.

Default Value:null
requestOptions Object inherited

The options to be used for data requests. These options can also be controlled through the requestOptions method parameter.

returnM Boolean
Since: ArcGIS API for JavaScript 4.13

If true, m-values will be included in the results if the features have m-values. Otherwise, m-values are not returned. The default is false.

Default Value:false
returnZ Boolean
Since: ArcGIS API for JavaScript 4.13

If true, z-values will be included in the results if the features have z-values. Otherwise, z-values are not returned. The default is false.

Default Value:false
url String

ArcGIS Server Rest API endpoint to the resource that receives the geoprocessing request.

Method Overview

Name Return Type Summary Class
Promise<JobInfo>more details

Cancels an asynchronous geoprocessing job.

more detailsGeoprocessor
Promise<JobInfo>more details

Sends a request to the GP Task for the current state of the job identified by jobId.

more detailsGeoprocessor
Promise<Object>more details

Sends a request to the server to execute a synchronous GP task.

more detailsGeoprocessor
Promise<ParameterValue>more details

Sends a request to the GP Task to get the task result identified by jobId and resultName.

more detailsGeoprocessor
Promise<ParameterValue>more details

Sends a request to the GP Task to get the task result identified by jobId and resultName as an image.

more detailsGeoprocessor
Promise<MapImageLayer>more details

Get the task result identified by jobId as an MapImageLayer.

more detailsGeoprocessor
Promise<JobInfo>more details

Submits a job to the server for asynchronous processing by the GP task.

more detailsGeoprocessor
Promise<JobInfo>more details

Resolves when an asynchronous job has completed.

more detailsGeoprocessor

Method Details

cancelJob(jobId, requestOptions){Promise<JobInfo>}

Cancels an asynchronous geoprocessing job. Requires an ArcGIS Server 10.1 service or greater.

Parameters:
jobId String

A string that uniquely identifies a job on the server. It is created when a job is submitted for execution and later used to check its status and retrieve the results.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
Type Description
Promise<JobInfo> When resolved, returns a JobInfo.
checkJobStatus(jobId, requestOptions){Promise<JobInfo>}

Sends a request to the GP Task for the current state of the job identified by jobId.

Parameters:
jobId String

The jobId returned from JobInfo.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
Type Description
Promise<JobInfo> When resolved, returns a JobInfo.
execute(params, requestOptions){Promise<Object>}

Sends a request to the server to execute a synchronous GP task.

Parameters:
params Object

Specifies the input parameters accepted by the task and their corresponding values. These input parameters are listed in the parameters field of the associated GP Task resource. For example, assume that a GP Task resource has the following input parameters:

  • <GPFeatureRecordSetLayer> Input_Points
  • <GPDouble> Distance

The params argument would then be an Object of the form:

{
 Input_Points: <FeatureSet>,
 Distance: <Number>
}

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
Type Description
Promise<Object> When resolved, returns an object with the following properties:
{
  messages: <GPMessage[]>,
  results: <ParameterValue[]>
}
See the GPMessage and ParameterValue classes for more information about the information in this object.
getResultData(jobId, resultName, requestOptions){Promise<ParameterValue>}

Sends a request to the GP Task to get the task result identified by jobId and resultName.

Parameters:
jobId String

The jobId returned from JobInfo.

resultName String

The name of the result parameter as defined in Services Directory.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
Type Description
Promise<ParameterValue> When resolved, returns an object with a property named result of type ParameterValue, which contains the result parameters and the task execution messages.
getResultImage(jobId, resultName, imageParams, requestOptions){Promise<ParameterValue>}

Sends a request to the GP Task to get the task result identified by jobId and resultName as an image.

Parameters:
jobId String

The jobId returned from JobInfo.

resultName String

The name of the result parameter as defined in the Services Directory.

imageParams ImageParameters

Specifies the properties of the result image.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
Type Description
Promise<ParameterValue> When resolved, returns an Object with a mapImage property of type MapImage
getResultMapImageLayer(jobId){Promise<MapImageLayer>}
Since: ArcGIS API for JavaScript 4.1

Get the task result identified by jobId as an MapImageLayer.

Parameter:
jobId String

The jobId returned from JobInfo.

Returns:
Type Description
Promise<MapImageLayer> A promise resolving to an instance of MapImageLayer.
Example:
// Get the resulting map image layer from a completed geoprocessing job.
geoprocessor.getResultMapImageLayer(jobInfo.jobId)).then(function(layer){
  view.map.add(layer);
});
submitJob(params, requestOptions){Promise<JobInfo>}

Submits a job to the server for asynchronous processing by the GP task. The method will resolve immediately after the job has been submitted to the server. Use waitForJobCompletion() to be notified when the job has completed and optionally periodic job status.

The task execution results can be retrieved using the getResultData(), getResultImage(), or getResultMapImageLayer() methods.

Parameters:
params Object

specifies the input parameters accepted by the task and their corresponding values. These input parameters are listed in the parameters field of the associated GP Task resource. For example, assume that a GP Task resource has the following input parameters:

  • <GPFeatureRecordSetLayer> Input_Points
  • <GPDouble> Distance

The params argument would then be an Object of the form:

{
  Input_Points: <FeatureSet>,
  Distance: <Number>
}

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
Type Description
Promise<JobInfo> When resolved, returns a JobInfo.
waitForJobCompletion(jobId, options){Promise<JobInfo>}
Since: ArcGIS API for JavaScript 4.13

Resolves when an asynchronous job has completed. Optionally job progress can be monitored.

Parameters:
Specification:
jobId String

The jobId returned from JobInfo.

options Object
optional

Options. See properties below for object specifications.

Specification:
interval Object
optional
Default Value: 1000

The time in millisecond between remote job status requests.

signal Object
optional

AbortSignal allows for cancelable asynchronous job. If canceled, the promise will be rejected with an error named AbortError.

statusCallback Object
optional

Callback function that is called at the specified interval. Use this method to monitor job status and messages.

Returns:
Type Description
Promise<JobInfo> When resolved, returns a JobInfo.
Example:
// Submit an asynchronous geoprocessing job. Display the remote job status every 1.5 seconds.
// When the job has completed at the output as a MapImageLayer.
let startDate = "1998-01-01 00:00:00";
let endDate = "1998-05-31 00:00:00";
let params = {
  query: "(Date >= date '" + startDate + "' and Date <= date '" + endDate + "')"
};

let geoprocessor = new Geoprocessor({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot",
  outSpatialReference: SpatialReference.WebMercator
});

geoprocessor.submitJob(params).then(function(jobInfo) {
  let jobid = jobInfo.jobId;

  let options = {
    interval: 1500,
    statusCallback: function(j) {
      console.log("Job Status: ", j.jobStatus);
    }
  };

  geoprocessor.waitForJobCompletion(jobid, options).then(function() {
    let layer = geoprocessor.getResultMapImageLayer(jobid);
    map.add(layer);
  });
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.