Best way to return whether a feature falls within a polygon?

590
2
Jump to solution
07-11-2017 11:56 AM
AndrewValenski__IT_
Occasional Contributor III

This is a fairly simple question: what is the best way to run a binary (yes/no) query to let me know if a point/polygon/line falls within an area. The use case is this: I have a parcel and want to return whether it falls within like five zones. I'm looking for a python solution if possible, as this will be iframed into a pop-up result in a custom Web App. 

All I need is a 'yes' or 'no' result from the queries. Please help!

0 Kudos
1 Solution

Accepted Solutions
AllanLaframboise
Occasional Contributor III

I'm sure you can do this with Python but if the data are stored in ArcGIS feature services, then you can use any language to make a REST API call with the appropriate spatialRelationship operator and parameters.  See the layer query doc here ArcGIS REST API .

Here's an example of a REST request that will return the state that intersects the given point:

https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_States_Generalized/FeatureServ... 

View solution in original post

2 Replies
AllanLaframboise
Occasional Contributor III

I'm sure you can do this with Python but if the data are stored in ArcGIS feature services, then you can use any language to make a REST API call with the appropriate spatialRelationship operator and parameters.  See the layer query doc here ArcGIS REST API .

Here's an example of a REST request that will return the state that intersects the given point:

https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_States_Generalized/FeatureServ... 

AndrewValenski__IT_
Occasional Contributor III

This is actually perfect. You can execute the proper spatial queries both Map & Feature services, which is perfect. 

Springboarding off of that realization -- are you familiar with a JS / Python code snippet that has an if/else statement for REST endpoint responses? My end-use is this: Hitting a webpage will trigger several of these spatial queries and return whether the point is in a number of areas (i.e. housing development area, wetland, etc.). I'm looking for a boolean logic of yes/no, so I imagine I could write a JSON parser to look for a !='No Record Found' and either print 'Yes' or 'No' depending on the response... 

Do you know of any samples out there for parsing the REST API's responses? 

0 Kudos