OSRM, (which stands for Open Source Routing Machine), is a robust routing engine known for its high-performance capabilities. It is specifically designed to calculate optimal routes for different modes of transportation, including driving, walking, and cycling. As an open-source project, OSRM offers a software library and a suite of tools that facilitate efficient route planning and navigation.
At its core, OSRM leverages OpenStreetMap (OSM) data, a collaborative mapping initiative providing freely accessible and editable maps of the entire global region. By processing OSM data, OSRM constructs a comprehensive network representation of the road system, encompassing critical details such as road types, intersections, and related attributes.
While OSRM may not attract as many eyeballs such as Graphhopper and Valhalla, it has a place in your Geospatial Toolbox, for the following reasons:
- It is very easy to get it up and running on a windows machine. No need to install Java, and have loads of Memory at your disposal. No need for Docker. No need for mucking around on the command line, and installing dependencies to get it to build.
- Unlike the open source version of Graphhopper, you have access to the Matrix API and the Travelling Salesman Solver.
- While it may not be as fast as Valhalla, it is more than adequate if you just want to query it locally. I usually get sub 100 ms responses, even if the start and end point are 1000's of km away.
Just how easy is it to get it up and running? You should be able to do this in just a few easy steps steps:
- Download the Road data from OSM, either from Geofabrik, or bbbike. Only make sure that it is .osm.pbf format
- Download the windows binaries from here: https://build.project-osrm.org/ Yes, they are old, but they work. If you want new version of OSRM, you can build it yourself.
- Extract the binaries, and copy the osm file in that same folder. On the command line, you need to run the following 4 steps.
- osrm-extract –p profile.lua data.osm.pbf
- osrm-partition data.osrm
- osrm-customize data.osrm
- osrm-routed --algorithm=MLD data.osrm?
Your OSRM engine is now ready to do routing for you. You can check it by making a request such as: https://127.0.0.1:5000/route/v1/driving/72.87139,19.25711;72.83365,18.92210?steps=true
What did these commands do?
- osrm-extract: This tool is responsible for extracting data from OpenStreetMap (OSM) files and converting it into a format suitable for OSRM. It processes OSM data and filters out the required road network information, such as geometry, connectivity, speed limits, and turn restrictions. The extracted data is then transformed into a specialized format optimized for efficient route calculations in OSRM.
- osrm-partition: Once the data is extracted, the osrm-partition tool performs a spatial partitioning of the road network. It divides the network into smaller sections based on geographic regions, typically using a technique like recursive space partitioning (e.g., the recursive bisection method). This partitioning enables efficient processing of route calculations by dividing the workload into manageable portions, reducing memory consumption, and improving overall performance.
- osrm-customize: The osrm-customize tool is responsible for optimizing the partitioned data to further enhance the routing performance. It applies various preprocessing techniques to the partitioned network, including node-based contraction hierarchies. Contraction hierarchies are a graph optimization method that allows for faster routing queries by precomputing and storing additional information about the road network. This optimization step significantly reduces the time required to calculate routes during runtime.
- osrm-routed: The osrm-routed binary serves as the routing server, offering the actual routing functionality. It sets up a server that listens for routing requests from clients and provides responses with calculated routes. When a client sends a routing request, osrm-routed processes the query using the preprocessed and optimized road network data. It employs efficient algorithms to calculate the shortest or fastest route based on the specified parameters. The server generates a response containing route information, including waypoints, geometry, travel distance, estimated travel time, and turn-by-turn instructions.
You should look at the API docs to really understand what you can do: https://project-osrm.org/docs/v5.24.0/api/
And this is not the end of it; If you want to explore further:
Happy Hacking & Happy Routing!
Senior Backend Developer (Node.js/Nest.js)
1 年Thanks for sharing such a great article. Have you also been able to run Map-Matching services on your end?
Delivery Lead| CRM & GIS Solutions Architect- IoT| Prince2|Project Management | Azure & Data Engineering| Scientist, Ex- ISRO
1 年Hi Dev looks great. Can we deploy on azure web app?
GIS ? Product Management ? AI & OSS Nerd
1 年Great work, but it shows the wrong values when I check with the Demo portal. Please check the bike mode.
Educator | Founder @ Spatial Thoughts | spatialthoughts.com
1 年Nice! Does this work on Wondows? I remember having to go the docker route for making it work on Windows.
Project Manager - GIS
1 年https://router.project-osrm.org/route/v1/driving/10.16196,76.23302;10.11870,76.28983?geometries=geojson {"code":"Ok","routes":[{"geometry":{"coordinates":[[15.404574,76.999993],[15.404574,76.999993]],"type":"LineString"},"legs":[{"steps":[],"summary":"","weight":0,"duration":0,"distance":0}],"weight_name":"routability","weight":0,"duration":0,"distance":0}],"waypoints":[{"hint":"Ls0viLaplogWAAAAAAAAABU5AAAAAAAATPjDQAAAAADorH1FAAAAABYAAAAAAAAAFTkAAAAAAACj3waAHg7rADntlgQoD5sAPDmLBJsA7wttjtfi","distance":160226.108106822,"name":"","location":[15.404574,76.999993]},{"hint":"Ls0viLaplogWAAAAAAAAABU5AAAAAAAATPjDQAAAAADorH1FAAAAABYAAAAAAAAAFTkAAAAAAACj3waAHg7rADntlgQsZpoAJheMBJsA7wttjtfi","distance":157894.215506382,"name":"","location":[15.404574,76.999993]}]} How can I plot this result to map?