Can we check if polygon contains multipoint latlon?

348
1
05-18-2022 08:30 PM
SriharshaK
New Contributor II

Hello I am trying to check if a polygon contains all points. Currently I could do with single point, but unable to do with multipoint. Is looping the best way possible or I am missing on alternatives.

 


if(polygon.rings.length > 0){
polygon.removeRing(polygon.rings.length-1);
}

myFeatureLayer.queryFeatures(query).then(function (response) {
if (response.features.length > 0) {
polygon.addRing(response.features[0].geometry["rings"][0]);
if (response.features[0].geometry["rings"]) {
view.graphics.add(polygonGraphic);
if(forecastLatLonX && forecastLatLonX.length > 0){
var pointX = new Point({
latitude: forecastLatLonX[0][1],
longitude: forecastLatLonX[0][0]
});
 
const contains = polygon.contains(pointX);
console.log("contains", contains);
}
view.graphics.add(pointGraphic);
}
}
});
Tags (3)
0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

I think what you're looking for is geometryEngine.contains:

if (geometryEngine.contains(polygonGeometry, multiPointGeometry)) {
	//do something
}

 

0 Kudos