Obtaining List of Coordinates for Route Along Nearest Edge Using OSMnx, Python and Leaflet

37 views Asked by At

I am currently working on a mapping project using Leaflet, where I need to obtain a list of coordinates representing a route between an origin marker and a destination marker. Specifically, I want the route to start along the edge closest to the starting or finishing coordinates, and then follow the exact path of the route.

Here's what I've done so far:

  • I successfully obtained coordinates for both the origin and destination markers using Leaflet.

  • I used functions like nearest_edges and nearest_nodes to find the closest edge and node for both the origin and destination coordinates.

  • I developed logic based on the direction of the edge and whether the node is on the edge.

  • I used the interpolate_points function to divide the starting and finishing edge using its linestring and calculate the distance to the origin/destination coordinate to determine the starting point.

  • From there, I generated a list of coordinates from the point on the edge to the nearest node for both the origin and destination.

  • To complete the route, I obtained the route using shortest_path and retrieved the linestring for every edge in it. Then, I inserted these linestrings between the starting and finishing segments to generate a complete list of coordinates.

However, I believe there might be a more efficient or straightforward approach to accomplish this task. I'm particularly interested in methods that allow me to obtain a list of coordinates for a route that can start in the middle of an edge.

Any insights, suggestions, or alternative methods would be greatly appreciated. Thank you!

Edit: Here is a link to a simplified version of my code.

0

There are 0 answers