AnsweredAssumed Answered

Get intersected polygons geometry based on polygons

Question asked by kshah77 on Jan 31, 2018
Latest reply on Feb 15, 2018 by kshah77

Hi,

 

I need help on getting polygons based on intersecting polygon in web map using arcgis javascript api. Say there is base polygon A and when the user edit polygon B over the multiple polygon A, the polygon B gets intersected/splited based on polygon A (please see the attached figure). So far I can do inside the base polygon but is there way I can query to obtain the geometry outside of the base polygon Is there any code snippet or sample/template to achieve this task? 

Here is my snippet:

IntersectingPolygon.on("edits-complete", modifyFeature);

function modifyFeature(evt) {
var queryFeatureWithId = new Query();
queryFeatureWithId.objectIds = [evt.adds[0].objectId];
queryFeatureWithId.outFields = ["*"];
queryFeatureWithId.num = 1;
queryFeatureWithId.outSpatialReference = map.spatialReference;
queryFeatureWithId.spatialRelationship = Query.SPATIAL_INTERSECTS;
queryFeatureWithId.returnGeometry = true;

var addedFeature = null;
var addedFeatureObjectId = evt.adds[0].objectId;

//use the feature's object id to get the feature's geometry
IntersectingPolygon.queryFeatures(queryFeatureWithId, function(featureSet){
if(featureSet.features.length == 0) {
return;
}
addedFeature = featureSet.features[0];

var queryOverlappingOuterPolygon = new Query();
queryOverlappingOuterPolygon.geometry = addedFeature.geometry;
queryOverlappingOuterPolygon.num = 1;
queryOverlappingOuterPolygon.outSpatialReference = map.spatialReference;
queryOverlappingOuterPolygon.spatialRelationship = Query.SPATIAL_REL_RELATION;

//query overlapping feature on ExistingPolygon
ExistingPolygon.queryFeatures(queryOverlappingOuterPolygon, function(overlappingFeatureSet) {
if(overlappingFeatureSet.features.length == 0) {
return;
}
var differenceGeometry = geometryEngine.intersect(addedFeature.geometry, overlappingFeatureSet.features[0].geometry);
//modify added feature geometry so that the feature resides within the boundary of outer polygon feature
addedFeature.geometry = differenceGeometry;
IntersectingPolygon.applyEdits(null, [addedFeature], null);

var queryOverlappingInnerPolygon = new Query();
queryOverlappingInnerPolygon.geometry = addedFeature.geometry;
queryOverlappingInnerPolygon.outSpatialReference = map.spatialReference;
queryOverlappingInnerPolygon.spatialReference = Query.SPATIAL_INTERSECTS;


});

});
}

 

Thanks,

 

Kush

Attachments

Outcomes