Query point inside polygon

938
2
Jump to solution
10-15-2019 09:08 AM
ScottWilson2
New Contributor II

I'm in a position where i have something working with the JavaScript API and now i'm trying to replicate it with the online Query Builder tool!

Here's my QueryTask which is successfully finding the point inside a polygon:

var residualWasteRequest = function(response, textStatus, xhr)
 {
   var residualWasteRest = "https://myserver.com/external/rest/services/Map_Services/MapServer/0";
 
   var query = new Query();
   var queryTask = new QueryTask(residualWasteRest);
   query.outSpatialReference = { wkid: 102100 }; 
   query.where = "1=1";
   query.outFields = ["*"];
   query.returnGeometry = true;
   queryTask.execute(query, qtResponse);
}‍‍‍‍‍‍‍‍‍‍‍‍


function qtResponse(results) {


    var x = -488287.0574008291;
    var y = 7519911.928379749;

    var point = new Point(x, y, new SpatialReference({ wkid: 102100 }) );


    for (var item in results.features) {

        var polygon = results.features[item].geometry;

        if (polygon.contains(point)){
            console.log("point is inside a polygon: " + 
            results.features[item].attributes.OBJECTID);
            map.centerAndZoom(point, 17); 
        } 
    }

}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Result:

point is inside a polygon: 18

Here's my equivalent query with the online tool:

I'm getting No records found.

What am i doing wrong?

thanks

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Scott,

   Change Spatial Relationship to intersects.

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Scott,

   Change Spatial Relationship to intersects.

ScottWilson2
New Contributor II

Hi Robert, changing Spacial Relationship to Intersects works a treat, thanks for your help

0 Kudos