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.
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?
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.
Because of projection-on-the-fly, seeing them overlapping onscreen is absolutely no guarantee that they are in the same coordinate system
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.