Or a tuple of (u, v, key, geom, dist) if return_geom and return_dist are True.
// convert lat,lng (y,x) point to x,y for shapely distance operation
xy_point = Point(reversed(point))
// calculate euclidean distance from each edge"s geometry to this point
gs_edges = utils_graph.graph_to_gdfs(G, nodes=False)["geometry"]
uvk_geoms = zip(gs_edges.index, gs_edges.values)distances = ((uvk, geom, xy_point.distance(geom)) for uvk, geom in uvk_geoms)
// the nearest edge minimizes the distance to the point
(u, v, key), geom, dist = min(distances, key=lambda x: x[2])
utils.log(f"Found nearest edge ({u, v, key}) to point {point}")
After Change
Or a tuple of (u, v, key, dist) if return_dist is True.
Or a tuple of (u, v, key, geom, dist) if return_geom and return_dist are True.
ne, dist = nearest_edges(G, X=[point[1]], Y=[point[0]], return_dist=True)
u, v, key = ne[0]
geom = utils_graph.graph_to_gdfs(G, nodes=False).loc[(u, v, key), "geometry"]
if return_dist and return_geom:
return u, v, key, geom, dist[0]