Spatial Query For Points Within Polygon

1353
3
Jump to solution
10-02-2018 09:21 AM
JosephEastman
New Contributor

I'm having a lot of trouble running a spatial query to find all features that intersect with a polygon.

I've got a hosted feature service made up of polylines that represent water mains in a distribution system. What I'm trying to do is a spatial query that takes a polygon, made up of a series of latitudes and longitudes, and finds all features of the hosted feature service that intersect (or fall within) that polygon. I've been using the query tool on the service url to help troubleshoot and this is what I'm doing right now:

The beginning point and ending point are the same as required, I know you can't see it in the screenshot. One interesting thing is that this requires a WHERE clause to run. To work around this I've place "1=1" in the where clause so that I get all of the results. The problem here is that I literally get every single feature, not just what intersects the polygon.

Is there any way to achieve what I'm after? I have searched stackoverflow, geoNet and google for many hours and tried many iterations and cannot for the life of me get this to work. Any help is appreciated!

0 Kudos
1 Solution

Accepted Solutions
JosephEastman
New Contributor

[SOLVED]

Robert,

The clockwise direction was key to making this work, I missed that important factor! I also realized my query was not correctly formatted for the polygon. I had found an example that told me to format it as I have shown in the images, but that was wrong. I needed to format it in the same way as the JSON response format.

WHAT I HAD:

[[-84.501150208,42.6413587068],[-84.5007299597,42.6418125078],[-84.5011948403,42.6421347441],[-84.5009356319,42.6424767877],[-84.4989507973,42.6423978669],[-84.4980388462,42.6429174009],[-84.4977169811,42.6425425286],[-84.5010250027,42.640878621],[-84.501150208,42.6413587068]]

WHAT IS CORRECT:

{"rings":[[[-84.501150208,42.6413587068],[-84.5007299597,42.6418125078],[-84.5011948403,42.6421347441],[-84.5009356319,42.6424767877],[-84.4989507973,42.6423978669],[-84.4980388462,42.6429174009],[-84.4977169811,42.6425425286],[-84.5010250027,42.640878621],[-84.501150208,42.6413587068]]],"spatialReference":{"wkid":4326}}

My final query string was as follows:

https://xxxxxxxxx.arcgis.com/xxxxxxxxxxxxxxx/arcgis/rest/services/FeatureName/FeatureServer/0/query?...

Thanks for the help!

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Joseph,

   Using a where clause of 1=1 will return all the feature period. When doing a spatial query you should not use 1=1 in the where. Also you need to ensure that your points make the polygon are listed in a clockwise direction or the query will fail.

JosephEastman
New Contributor

[SOLVED]

Robert,

The clockwise direction was key to making this work, I missed that important factor! I also realized my query was not correctly formatted for the polygon. I had found an example that told me to format it as I have shown in the images, but that was wrong. I needed to format it in the same way as the JSON response format.

WHAT I HAD:

[[-84.501150208,42.6413587068],[-84.5007299597,42.6418125078],[-84.5011948403,42.6421347441],[-84.5009356319,42.6424767877],[-84.4989507973,42.6423978669],[-84.4980388462,42.6429174009],[-84.4977169811,42.6425425286],[-84.5010250027,42.640878621],[-84.501150208,42.6413587068]]

WHAT IS CORRECT:

{"rings":[[[-84.501150208,42.6413587068],[-84.5007299597,42.6418125078],[-84.5011948403,42.6421347441],[-84.5009356319,42.6424767877],[-84.4989507973,42.6423978669],[-84.4980388462,42.6429174009],[-84.4977169811,42.6425425286],[-84.5010250027,42.640878621],[-84.501150208,42.6413587068]]],"spatialReference":{"wkid":4326}}

My final query string was as follows:

https://xxxxxxxxx.arcgis.com/xxxxxxxxxxxxxxx/arcgis/rest/services/FeatureName/FeatureServer/0/query?...

Thanks for the help!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

No problem.

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos