Select to view content in your preferred language

Get intersected polygons geometry based on polygons

1496
1
01-31-2018 12:50 PM
KushendraShah1
Emerging Contributor

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

0 Kudos
1 Reply
KushendraShah1
Emerging Contributor

I have some progress on intersecting the polygon inside of multiple polygon but I want to split into individual geometry with respective objectID. Is there anyway or API reference to achieve this geoprocessing task?

Here is the snippet:

//query overlapping feature on ExistingPolygon
ExistingPolygon.queryFeatures(queryOverlappingOuterPolygon, function(overlappingFeatureSet) {


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

//query overlapping features on IntersectingPolygon
ExistingPolygon.queryFeatures(queryOverlappingOuterPolygon, function(overlappingFeatureSet) {
if(overlappingFeatureSet.features.length == 0 || overlappingFeatureSet.features.length == 1) {
return;
}
var geometryArr = [];
for(var index = 0; index < overlappingFeatureSet.features.length; index++) {
if(addedFeature.attributes["OBJECTID_1"] !== overlappingFeatureSet.features[index].attributes["OBJECTID_1"]) {
geometryArr.push(overlappingFeatureSet.features[index].geometry);
}
}
//union of all overlapping features
var unionGeometry = geometryEngine.union(geometryArr);
//modify added feature geometry so that the feature does not overlap other features in IntersectingPolygon
var differenceGeometry = geometryEngine.intersect(addedFeature.geometry, unionGeometry);
addedFeature.geometry = differenceGeometry;
IntersectingPolygon.applyEdits(null, [addedFeature], null);
});

});

0 Kudos