0

I want to generate a route between origin and destination location using NetworKX and OSMnx.

The origin is the green dot and the black one is the destination.

My constraints are the blue circle which are locations I must pass throw their areas. enter image description here

My idea was to find the shortest path between the origin to the first blue circle, from the first to the second, etc. But I don't know how to make the program decide which one will be the first blue circle.

I thought to calculate the route between each blue circle to the origin but in the case of a lot of blue circles it could be a lot of computation. Any ideas about how to choose the first one or to reconstruct the trajectory between the origin and the destination?

Roy Ancri
  • 119
  • 2
  • 14
  • 1
    I'm not familiar with Python, but in C++ I used Boost Graph Library, Dijkestra Algorithm to solve similar issue with shortest path problem between 2 points, you can make each path between 2 points starting from green passing to blue, later you accumulate all shortest paths together to form your path. Of course at first you should build a graph using nodes of OSM file, and pass that graph to Dijkestra Algorithm. – Bilal Dec 28 '19 at 13:04
  • Thank you, did you mean that I should make a path between the green to all blue circles? this is what I want to avoid. And what do you mean by building a graph? – Roy Ancri Dec 28 '19 at 13:10
  • As I understand, you want reduce computation cost related to looking for each shortest path separately among your points, is that what you want achieve ? building a graph, means to assign your nodes in the OSM file to a Vertices in the graph, and you assign Edges of the graph with respect to connectivity and weight of the edges between your nodes – Bilal Dec 28 '19 at 13:53
  • Yes, the calculation is n^2 for finding the distance between each location to all other locations so maybe it is too much. The nodes are already in this OSM file, this is what to function "graph_from_bbox" is doing. Am I wrong? – Roy Ancri Dec 28 '19 at 14:29

1 Answers1

0

You can use OSMnx to calculate a vectorized great-circle distance between your origin and each of the blue points, then take the nearest as the first to pass through: https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.utils.great_circle_vec

This offers a rough approximation of which is closest to your origin, without having to do the expensive computation of all the shortest paths. Alternatively, if these blue points are time stamped, you could sort them by timestamp and then calculate routes through them accordingly.

gboeing
  • 5,691
  • 2
  • 15
  • 41
  • Thank you for commenting, the problem with the great-circle distance is that the closest blue point is not always the closest if I'm using my car but it is a starting point and then I can compare the driving distance only between the 2-3 closest blue circles according to your method. – Roy Ancri Jan 06 '20 at 20:53
  • As you can see the second and third blue circles from the left side are near to a yellowish road and I want my path will use this road but the closest node to the blue circle is not a point on this road. Is there a way to generate a path that will use this road and not pass throw the closest node to these blue circles? – Roy Ancri Jan 07 '20 at 16:10