Troubleshooting geoprocessing tasks in web applications
In this topic
Input feature set schema
When executing a geoprocessing task, the web application converts the parameters into JSON and sends it to the geoprocessing service for execution. The ArcGIS Server parses the JSON sent from the client and converts them to appropriate data objects (ArcObjects). The GPFeatureRecordSetLayer parameters are converted to a feature set based on the schema properties geometryType, spatialReference, and fields defined in the JSON. If the properties are not specified in the JSON, the ArcGIS Server inherits the properties from the default schema defined for the feature set. The task may fail because of the ambiguities in the input values and the default schema. To avoid failures, as a web developer, you should set these properties when creating feature sets. The JavaScript code below shows how to set the fields, spatialReference, and geometryType properties of a feature set created from a feature layer in the web application.
Creating feature sets from featureLayer in JavaScript APIfunction getFeatureSetFromFLayer(){
//create featuresets
var featureSet = new esri.tasks.FeatureSet();
//get featurelayer from map's featurelayer (ex:myFeatureLayer)
var layer=map.getLayer("myFeatureLayer")
//get features from featurelayer
featureSet.features = layer.graphics;
//assign fields property
featureSet.fields=layer.fields;
//assign map's spatial reference
// Assumption: map variable is esri.Map instance in the application
featureset.spatialReference=map.spatialReference;
//assign geometryType
featureSet.geometryType=layer.geometryType;
return featureSet;
}
Tip:
The input feature sets created in web applications are usually in Web Mercator (wkid:4326) or Web Mercator Auxiliary Sphere (wkid:102100)) projections. However, the underlying model or script of the geoprocessing task may use other datasets as project data that are in a different spatial reference. In some cases, if the spatial reference of the input feature sets and the task's project data are different, the task may fail. This is due to the task author not anticipating receiving features in different spatial references than the project data. The Spatial reference considerations for geoprocessing services topic discusses some solutions for the task author to avoid such failures.Output spatial reference (coordinate system)
The spatial reference of the output feature sets is dependent on the input parameters and other datasets that are used in the model or script. Web applications assume the spatial reference of the output features are in the same spatial reference as its map instance (esri.Map). Hence, the features may not be rendered as expected. To avoid such ambiguities, you should set the outSpatialReference property of the geoprocessing instance to the map's spatial reference as shown in the code below. When the output spatial reference property is set, the server will return the output features sets in the requested outSpatialReference.
Setting outSpatialReference in JavaScript API
var gpTask = new esri.tasks.Geoprocessor(
"http://<gp-task-url>");
//map is assumed to be the map instance of the web application
gpTask.outSpatialReference=map.spatialReference;