Select to view content in your preferred language

ArcGIS Online Polygon containing a point

1419
4
09-25-2017 11:27 PM
DeepakSwamy
Emerging Contributor

Hi,

I have a feature layer containing polygons. How do I find if a point lies within any of the polygons in shapefile? I am using ArcGIS Online and ArcGIS API for Python.

I was able to extract features from the feature layer and could convert feature to polygon.

I constructed arcgis.geometry.point object from X, Y.

However polygon.contains(point) is not returning any result.

Please help.

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

The obvious questions,.... are the polygon and the point in the same coordinate system? are both systems defined? have you switched the values for X and Y?

DeepakSwamy
Emerging Contributor

Yes, both are in same coordinate system. I can see both polygon and point features in the map view. I can see that in map view point is contained within the polygon. I have derived polygon and point from the geometry of the features seen on the map. However polygon.contains(point) returns 'None' as response. Not sure what am I doing wrong.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Because of projection-on-the-fly, seeing them overlapping onscreen is absolutely no guarantee that they are in the same coordinate system

0 Kudos
by Anonymous User
Not applicable

This seems to be a very old post but sharing as it might help someone else. if you want to search a point geometry within a polygon, you will have to use within filter while doing spatial query on polygon layer.

Code Example:

pt = Point({"x" : -10392706.32194956, "y" : 5622351.110157302, "spatialReference" : {"wkid" : 4326 }}) //constructing point geometry


gf = within(pt,sr=4326) // this is geometry_filter we are creating which will be passed in the query below. you will have to import within filter from arcgis.geometry.filters import within

polygon_features = polygon_layer.query(where='1=1',geometry_filter=gf,out_fields='field1,field2',return_geometry= False) // if you want polygon geometry to be returned then remove return_geometry= False.

0 Kudos