Intersect using the Geometry Service

4217
4
Jump to solution
08-28-2013 01:53 PM
RaghuVamshi
New Contributor
For an intersect operation using the geometry service, below is my code thus far. Something is not right as the intersect is not working and the geometry(ies) is not returned. Could you please suggest where I am wrong. Thanks in advance for your help.

Raghu

//perform intersect using geometry service function performIntersect(featureSet) { var geomService = new esri.tasks.GeometryService("https://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");     var geomSet = [];     for (var i = 0; i < featureSet.length; i++) {         geomSet.push(featureSet.geometry);     }      //get geometry from the graphic drawn by user on map     var geomDraw = esri.getGeometries(map.graphics.graphics);      //call the geometry intersect     geomService.intersect(geomSet, geomDraw, showIntersect);  //dont have an error handler, but runs through with no results }  //show the intersect geometries on map function showIntersect(intGeometries) {     var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,     new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0, 0.65]), 2), new dojo.Color([255, 0, 0, 0.35]));      dojo.forEach(intGeometries, function (geometry) {         var graphic = new esri.Graphic(geometry, symbol);         map.graphics.add(graphic);     }); }
0 Kudos
1 Solution

Accepted Solutions
VinayBansal
Occasional Contributor II
Are you accessing the Geometry Service over SSL. Since you are using the https:// url for your geometry service.
If not, try accessing the service using http://
Also, have you included the geometry service url in proxy.config?

View solution in original post

0 Kudos
4 Replies
JasonZou
Occasional Contributor III
performIntersect(featureSet):

What is featureSet? If an array of graphics, that's fine.
If the same as a query result, then the code is incorrect. Should be
var geomSet = dojo.map(featureSet.features, function(aFeature) { return aFeature.geometry;});


esri.getGeometries
should be esri.graphicsUtils.getGeometries.

    //get geometry from the graphic drawn by user on map
    var geomDraw = esri.getGeometries(map.graphics.graphics);

    //call the geometry intersect
    geomService.intersect(geomSet, geomDraw, showIntersect);

getGeometries will return a geometry array, but the second parameter of geomService.intersect should be a single geometry, not a geometry array. Please refer to https://developers.arcgis.com/en/javascript/jsapi/geometryservice-amd.html#intersect.
0 Kudos
RaghuVamshi
New Contributor
Jason, many thanks for your suggestions on my code. I should have been more descriptive with my code, but you guessed right.

performIntersect(featureSet) - featureSet is a query result and not an array of graphics.
esri.getGeometries - realized it returns an array and was not passing the right parameter to the intersect command.

Made the updates to code, but still not able to get the geometry intersect to run correctly. Now it throws an error.

        var geoA = new Array();  //declared in initialize

        //user draws two polygons with overlap on the map using the draw tool and clicks on a button which calls performIntersect()
 function performIntersect() {
     alert('intersect..');
     //get the first drawn polygon
     var geomSet = geoA[0];
     //get the second drawn polygon
     var geomDraw = geoA[1];
     geomService.intersect([geomSet], geomDraw, showIntersect); //throws error when call made to geometry service URL
 }

 function showIntersect(intGeometries) {
     var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
     new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0, 0.65]), 2), new dojo.Color([255, 0, 0, 0.35]));
    
     //clear the graphics drawn
     map.graphics.clear();
     map.graphics.add(new esri.Graphic(intGeometries[0], symbol));
 }

//error thrown at the console -- dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"error":{"code":500,"message":"An unexpected error occurred processing the request.","details":["The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"]}});
0 Kudos
VinayBansal
Occasional Contributor II
Are you accessing the Geometry Service over SSL. Since you are using the https:// url for your geometry service.
If not, try accessing the service using http://
Also, have you included the geometry service url in proxy.config?
0 Kudos
RaghuVamshi
New Contributor
Vinay, appreciate you looking into this and pointing me in the right direction. I did not have a proxy page for this. Now its setup and the geometry service URL is included in the proxy.config file - hurray, the geometry service intersect works like a charm!

Yes, the app will be within a SSL but for testing over http. Thanks again!
0 Kudos