0

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.

3
  • Please provide a complete, minimal, reproducible code snippet for us to reproduce and troubleshoot.
    – gboeing
    Commented Feb 11 at 18:05
  • Also note that OSMnx builds graph models of the street network. A graph is a set of nodes linked to each other by a set of edges. There is no concept of a path along a graph starting in the middle of an edge: by definition, paths are between nodes. Thus, any such project would require some ad hoc geospatial work, as you noted.
    – gboeing
    Commented Feb 11 at 18:18
  • @gboeing Apologies in advance, I added a link to a file in my repository. I have tried reducing the code as much as possible. This is also my first time sharing code or asking a question, so it might be very noisy code. If you have any questions or comments, please let me know. Any type of feedback will be very appreciated. Commented Feb 13 at 5:12

0