I'm hoping to automate a process, and doing so involves a python script that can look at points on one feature layer, and determine which polygon, from another feature layer, that point is contained within.
Below, I have included some code that demonstrates my approach. In the end, I would hope for a result of 'True,' if the point was within the polygon, which in this case, it was. However, I get an empty result. This example only tests one point and one polygon, and both were selected because the point is within the polygon.
I've seen many other threads on this subject, but can't seem to find an example that shows how to prepare the point and polygon objects for the use of the 'within()' method.
from arcgis.gis import GIS
from arcgis.geometry import Geometry
from arcgis.geometry.filters import within
gis = GIS("https://www.arcgis.com", "UserName", "UserPass")
fl1 = gis.content.get('ece8ed133a2149f98f46fac2042db2f8')
query1 = fl1.layers[0].query()
resp1 = query1.features
resp1[0].geometry
# Output
# {'rings': [[[-10397275.0847498, 5628849.44085896],
# [-10385962.4045636, 5628773.00383067],
# [-10386038.8415919, 5618606.87906876],
# [-10397427.9588064, 5618606.87906876],
# [-10397275.0847498, 5628849.44085896]]]}
poly_geometry = Geometry(resp1[0].geometry)
fl2 = gis.content.get('d14af86121b640f68e050d20f3f0e876')
query2 = fl2.layers[0].query()
resp2 = query2.features
resp2[0].geometry
# Output:
# {'x': -10392706.32194956, 'y': 5622351.110157302}
point_geometry = Geometry(resp2[0].geometry)
print(point_geometry.within(poly_geometry))
# Output:
# None