Dijkstra’s algorithm weighted by travel time in OSM networks

Finding the fastest and shortest path with the OSMNX 1.6

Bryan R. Vallejo
Towards Data Science
7 min readJust now

Image by the Author. Fastest route (red) and Shortest route (orange) in Morocco example

The Shortest Path (Dijkstra’s) algorithm can be applied in OSM networks like driving, bike, and pedestrian, to find the most optime route between origin and destination. But, the algorithm calculates in the network the shortest routes based on distance and it does not really mean the most optime route. The distance in a road network can be relative when we consider the speed of the roads. Definitely, the most optime route between the two points might be the shortest if the road network has equal speed on all roads. In the case we compare the speed in highways with urban streets we will refactor this idea understanding that the most optime route is the fastest.

“The distance in a road network can be relative when we consider the speed of the roads”

Thanks to the Python library OSMNX, it is possible to add speed to different kinds of roads at the global level and calculate the Travel times between nodes in the OSM network. This allows the Python library to process the Shortest Path algorithm weighted by Travel times.

This practice is the continuation of a previous tutorial that used the Shortest Path algorithm to calculate the shortest route between two locations in Morocco.

Shortest route in OSM network in Morocco

Access coding tutorials

If you are not yet a member of

you will be required to subscribe to access the stories. You can follow more coding tutorials and support my work by joining using my personal link. Be part of this coding journey.

Join here 👉 https://bit.ly/3yjLsSL

OSM data license

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Geospatial Scientist | @BryanRVallejo | Supporting GIS community to automate spatial analysis | Get full access to my stories: https://bit.ly/3yjLsSL

Recommended from Medium

Lists

See more recommendations