so this sounds simple and if i use Near in Pro it is but i want to create a AGOL python notebook to run once a day to loop over any point features created that day and get the closest XY to a feature service of polylines (50k features)
i tried following the example here Part 3 - Spatial operations on geometries | ArcGIS API for Python
but even if i just manually populate the geomenty json for both the point and the polyline it returns None
Solved! Go to Solution.
Are you using a standard Notebook? I think you'd require an Advanced Notebook type to then be able to import the required ArcPy module.
access_res.type is probably returning none
Are you using a standard Notebook? I think you'd require an Advanced Notebook type to then be able to import the required ArcPy module.
access_res.type is probably returning none
thanks @DavidPike that was the issue
it looks like its returning the distance now but it looks like its in radians?
it also looks like its only getting the closest vertex rather than the closest point on the line unfortunately
Are you able to share the full code and possibly the mapped polyline and point inputs and point result? Values look like a spatial reference issue, possibly. I don't think there's any angles calculated so likely not radians.
I found the Python API Geometry Class docs to be a bit confusing as they suggested a result being a tuple of xy coords and the distance.
Then I found this https://community.esri.com/t5/arcgis-api-for-python-questions/need-query-point-and-distance-clarific...
which describes the actual result object (straight from the arcpy function). 😐
this is the code:
for xbsg in bsgPoints:
print(xbsg.attributes["objectid"])
print(xbsg)
access_point = Point(xbsg.geometry)
access_res = access_polyline.query_point_and_distance(access_point)
if (access_res):
print(access_res)
print("--++--")
print(access_res[0].JSON)
print("----")
this is the code's closest point
but i was expecting this as the closest point:
and this is the distances returned:
i also found that post and it suggests that the distance is the second item so
0.001106969364200805
From the geometry methods doc and the doc screenshot in that thread, the 2nd value appears to be the distance from the line start along the line. I think it's the 3rd value you're looking for. Without knowing more about your data etc. I'm not sure what may be happening with the results.
I'd print out the JSON of the inputs also and maybe something with the SRID/WKID might show up.
https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/geometry.htm
You can get the information for the output tuple from the ArcPy Polyline documentation.
this is the geometry of one of the polylines
{"geometry": {"paths": [[[-1.04626706475298, 52.5312679471987], ........ [-1.0447855316579, 52.5304270718345]]], "spatialReference": {"wkid": 4326, "latestWkid": 4326}}
this is the geometry for one of the points
{"geometry": {"x": -1.0453711186340822, "y": 52.53063399067387, "spatialReference": {"wkid": 4326, "latestWkid": 4326}}
thanks for the help
Stu
OK that's WGS84 and the lengths I guess are decimal degrees. Unless there's another Geodesic Method available I think you'd really need to project the coordinates into a planimetric coordinate system to get a meaningful output.