I met a lot of issues when I started the OSRM learning/research, so I built this document to help newcomers to avoid them.
Moreover, also some experiences recoreded.
Welcome everyone to make this document up to date!
- Based on revision:
commit e5d8319c43b454642079f66b930ac73803840e2b
I assume you already know basically what OSRM is.
If not, please start from :
- read the main page of osrm-backend
- try the demo server of OSRM
- quick view the OSRM API Documentation
There're totally 2 main repos for OSRM project, i.e. osrm-backend and osrm-frontend. What we will focus on is the osrm-backend repo, i.e. the routing engine.
OSRM is designed to run on OpenStreetMap data. For a quick introduction about how the road network is represented in OpenStreetMap and how to map specific road network features have a look at this guide about mapping for navigation.
There're also a lot of documents on osrm-backend wiki page which are very valuable for a quick view.
Even OSRM provides docker image to help us build our own OSRM service easier, building and debugging the source code can still help us to understand the project deeply.
Before you start, please
- use a Mac
- Actually OSRM can be built and run on many platforms, e.g. MacOSX, kinds of Linux, even native Windows (may not work, see Windows Compilation). But for debug the project, it's better to have a Mac with Xcode.
- get familiar with modern C++ (C++11/14)
- install pre-requirements: latest
git, cmake
Refer to below links for other dependencies and detailed build steps:
The current default build steps on MacOSX will not generate Xcode project. Also, try to generate Xcode project by cmake -G Xcode command can not work(see the still opened issue How to create Xcode project of osrm-backend on mac).
Fortunately @springmeyer have found the reason and give a temp workaround for us(please also refer to the answer from @springmeyer in How to create Xcode project of osrm-backend on mac):
- Go to local cloned
osrm-backendrepository. touch src/dummy.cpp- Apply a patch for CMakeLists.txt.
3.1 get patch file and put it in current folder
3.2git apply enable-xcode-project.diff
3.3 If the apply fails in the future when the original CMakeLists file has some extra changes, then you could manually add the diffs into it.
3.4 The idea is simple, somehow the targetslibosrm_store.aandlibosrm_updater.acan't be generated correctly, which makes linking can't be finished correctly. So we need to make a workaround to generate the targets. - Then run the following commands:
mkdir build
cd build
- Then you have two choices:
Build with Mason package manager (Recommended).
cmake ../ -G Xcode -DENABLE_MASON=ON -DBUILD_TOOLS=1
cmake --build .
Manually install all the dependencies. (You may need to install some specific one if Mason manager can't install if for you in the first way.)
brew install boost git cmake libzip libstxxl libxml2 lua tbb ccache GDAL (only select what you don't have)
cmake .. -G Xcode
cmake --build .
- You will find
OSRM.xcodeprojunderbuildfolder.
There're several runable binaries, i.e. osrm-components, osrm-contract, osrm-customize, osrm-datastore, osrm-extract, osrm-io-benchmark, osrm-partition, osrm-routed, most of them are used for pre-processing map data.
osrm-extract: Extract the road network(routing data) into a normalized format. It parses the contents of the exported OSM file and writes out routing metadata. More detailed refer to Extracting the Road Network (osrm-extract).- For the MLD(Multi-Level Dijkstra) pipeline we need to extract (
osrm-extract) a graph out of the OpenStreetMap base map, then partition (osrm-partition) this graph recursively into cells, customize the cells (osrm-customize) by calculating routing weights for all cells.- i.e. MLD data pre-processing pipeline:
osrm-extract->osrm-partition->osrm-customize
- i.e. MLD data pre-processing pipeline:
- For CH(Contraction Hierarchies) the partition and customize pipeline stage gets replaced by adding shortcuts from the Contraction Hierarchies algorithm (
osrm-contract).- i.e. CH data pre-processing pipeline:
osrm-extract->osrm-contract
- i.e. CH data pre-processing pipeline:
Please have a try by the Run the routing engine
- Open the Xcode project
- choose the target you wanted(e.g.
osrm-routed) - set the command line parameter:
Edit Scheme -> Run -> Arguments -> Arguments Passed On Launch - Run
- Enjoy!
Exported OSM data files can be obtained from providers such as Geofabrik.
I have tried to download the .osm.pbf file from Geofabrik, it works!
I also tried this on my Windows 10, so far it works.
- Build with VS2015
- There're some dependencies will be downloaded while run this
build-local.bat. Some of them you may already have and want to avoid the redundant download, you can try to edit thebuild-local.batandappveyor-build.bat.- e.g. If already have
cmake, change theSET CMAKE_VERSION=3.9.2with your current cmake version.
- e.g. If already have
- There're some dependencies will be downloaded while run this
cd osrm-backend
./build-local.bat
- Open Visual Studio 2015 Solution:
./build/OSRM.sln - Set Configuration to
RelWithDebInfo(Debugbuild failed) - Set
osrm-routedas Startup Project - Enjoy!
The document OSRM Processing Flow is a description from importing raw OSM data, to computing routes and serving requests. Very valuable for reference. Graph representation describe basic graph structure of OSRM.
This is a demo HTTP server on top of libosrm library, the core routing service engine. More detailed refer to Running the Engine via a HTTP Server (osrm-routed).