[GIS] Geoprocessing tool not executing when Map’s SpatialReference is Web Mercartor

arcgis-javascript-apicoordinate systemgeoprocessing-service

I am facing a strange issue when trying to execute GP service when my map's spatial-reference is Web Mercator. I appreciate all help.

I have a JavaScript API application. Initially I only had my map service used in this application. The Map Service I am using is in NAD27. I execute a GP service from JavaScript API and it works fine. In fiddler I can see the request being send to the server. Now I need to add ESRI image layer to map. So I now have my map's spatial reference as web mercarter. Now if I execute the GP Service nothing happens. No request being send to server, because nothing gets recorded in fiddler.

If I test the same request from ArcGIS Server rest end point it works fine.

Here is the request string in NAD27 and web mercarter. Only difference is wikid.

{"features":[{"geometry":{"type":"polygon","rings":[],"_ring":0,"spatialReference":{"wkid":4267,"latestWkid":4267}},"symbol":null,"attributes":{"id":1,"legalParams":"MT:TR|CNTY:051|STC:OH|PAR:|QQ:NW|LN:|PGUID:{3A15DFEB-9868-4588-9A08-737C033EDF2D}|MSC:1|STN:34|MER:01|TWSP:6|TDIR:N|RNG:5|RDIR:E|SEC:13|RW:|RUOM:AC"},"infoTemplate":null}],"spatialReference":{"wkid":4267,"latestWkid":4267},"geometryType":"esriGeometryPolygon","fields":[{"name":"Id","type":"esriFieldTypeOID"},{"name":"legalParams","type":"esriFieldTypeString"}]}

Web Mercator request

{"features":[{"geometry":{"type":"polygon","rings":[],"_ring":0,"spatialReference":{"wkid":102100,"latestWkid":3857}},"symbol":null,"attributes":{"id":1,"legalParams":"MT:TR|CNTY:051|STC:OH|PAR:|QQ:NW|LN:|PGUID:{3A15DFEB-9868-4588-9A08-737C033EDF2D}|MSC:1|STN:34|MER:01|TWSP:6|TDIR:N|RNG:5|RDIR:E|SEC:13|RW:|RUOM:AC"},"infoTemplate":null}],"spatialReference":{"wkid":102100,"latestWkid":3857},"geometryType":"esriGeometryPolygon","fields":[{"name":"Id","type":"esriFieldTypeOID"},{"name":"legalParams","type":"esriFieldTypeString"}]}

Best Answer

I am able to find the reason for the above error. It looks like an ESRI bug to me.

One of the parameter that I pass to gp.Execute() method is a FeatureSet. This FeatureSet contain a polygon with empty geometry and few attributes. My output will add geometry to this FeatureSet. When map's spatial reference is GCS, the GP tool works fine. But when the spatial reference is PCS, the FeatureSet requires some geometry for the polygon. I am not sure why it is so. So I am adding few dummy rings to the polygon to get it working.

The line polygon.addRing ... below was added to fix the issue discussed above. I guess we can add any dummy ring values there.

If anybody can give a better reason why this is only required when the spatial reference is PCS, I appreciate it.

    .....
    ......
    var attr = {"id":1, "legalParams":legalParams };      
    var polygon = new esri.geometry.Polygon(map.spatialReference);
    polygon.addRing([[-180,-90],[-180,90],[180,90],[180,-90],[-180,-90]]);//This line is added to fix the issue discussed above. This is not required for GCS
    var graphic = new esri.Graphic(polygon, null, attr, null);
    legalFeatureset = new esri.tasks.FeatureSet();
    legalFeatureset.spatialReference = map.spatialReference;
     .......
     ''''''
    var features = [];
    features.push(graphic);
    legalFeatureset.features = features;
    legalFeatureset.geometryType = "esriGeometryPolygon";

    .......
    ''''''' 
   gp.execute(params, drawGeoprocessingResult, getError);
Related Question