📜 ⬆️ ⬇️

We expand the service of building routes OSRM

More recently, in one of the projects, we were given the task of learning how to build routes on the map for cycling.

First of all, we started watching the Google and Yandex routes. And unfortunately, I had to give them up, because the first allowed to show them only on native maps, the second, did not know that there are bicycles and even pedestrians.

Having a little studied the subject area, we finally found what we were looking for: Open Source Routing Machine . The project is open source, which allows you to deploy on your server, your own service to build routes.
')


Tiles: MapBox , Yandex Maps
Map Data: OpenStreetMap Members

Having figured out how to configure and launch it, we decided to share it and retell the installation process in our own words, and that was what we had to face in the process.

In the project wiki , the installation process is described in some detail. The installation is described for various operating systems (Debian, CentOS, Mac OS X, etc.), problems are written when deployed on EC2 Micro, and for “advanced” there is a recipe for Chef.

We were lucky that we had Debian Wheezy (64) as the OS on the server. Because when reading documentation, it turns out that other systems have to take various additional steps. For example, on Debian Squeeze, it was necessary to upgrade the boost to version 1.44. But all this, thanks to the developers, is written in the documentation.

Our installation took 3 simple lines:

sudo apt-get install git libboost-dev gcc g++ make cmake libstxxl-dev \ libxml2-dev libbz2-dev zlib1g-dev libzip-dev libboost-filesystem-dev \ libboost-thread-dev libboost-system-dev libboost-regex-dev libboost-program-options-dev \ libboost-iostreams-dev libgomp1 libpng-dev libprotoc7 libprotobuf-dev protobuf-compiler \ liblua5.1-0-dev libluabind-dev pkg-config libosmpbf-dev 

 git clone https://github.com/DennisOSRM/Project-OSRM.git 

 mkdir -p build; cd build; cmake ..; make 


After that, after thinking a couple of minutes, the server reported that the build was successful.

Now, the next stage began, as it turned out the longest - the launch.

To start the server, it needs to prepare the data to build the graph. To download them, you need to extract them from the OpenStreetMap maps. This is done by the included utilities.

But first you need to download a map of the region for which you want to build routes.

Developers suggest using the GeoFabrik service. On which you can download maps for the mainland of the land, individual countries and regions. But, we wanted more, and we downloaded the entire map of the planet through Planet OSM .

Using the osrm-extract utility, the data is extracted from the map and saved for further download. Before extracting data, you must specify a profile file (profile.lua), which describes which routes are needed. All profiles are in the profiles folder in the root folder with sources and are connected by creating a link to the desired file.

ln -s ../profiles/bicycle.lua profile.lua

As you can see, we have specified a profile for cyclists. But, there are profiles for both road transport and pedestrians.
Also, you may need to specify a link to a folder with additional libraries.

ln -s ../profiles/lib/

After that, run the utility itself.

./osrm-extract map.osm

We must once again pay tribute to the developers - they honestly warned that the process was a long one, and even wrote that it took them 65 minutes on the configuration of the Core i7 with 8GB RAM and Samsung SATA 5400 RPM.

On our server (Core i5, 8GB RAM, 5400), a file with maps of 35 GB in size was eventually processed for 4 hours. Later we tried to take a map of the European part of Russia as an experiment - it took 30 minutes.

Developers advise to speed up, firstly, download maps in PBF format, and secondly, switch to SSD drives :)
And so, we got a file with the osrm extension. But, you need to use another utility from the kit - osrm-prepare.
It creates several files: hsgr - the hierarchy of routes, to find the most suitable, nodes - the route graph, and files with indexes. By running the utility,

./osrm-prepare map.osrm

we sat down to drink coffee, because The process once again took several hours. And so, seeing the cherished 100% on the screen, we launched the server itself:

./osrm-routed

But, before launch, as it turned out, you need to put, in the directory with the server, the server.ini initialization file. In it we specify which files and where to get, and several launch parameters.

 Threads = 4 IP = 0.0.0.0 Port = 5000 hsgrData=./map.osrm.hsgr nodesData=./map.osrm.nodes edgesData=./map.osrm.edges ramIndex=./map.osrm.ramIndex fileIndex=./map.osrm.fileIndex namesData=./map.osrm.names 


Hooray! The server started and blinked happily with lines telling us that it was ready to create routes. But looking at the returned JSON was not interesting. And in this case, the developers have a small web application for using OSRM.

Download the source at this address . We post them on a web server. No more additional settings should be done - just go to the page http: // <your-server> /osrm/main.html

By default, the application is configured on the OSRM demo server, but by opening the OSRM.config.js file we can change the server address to the one we installed by changing the url parameter in the ROUTING_ENGINES section.

And now we have our own route building service. Thanks for attention!

Source: https://habr.com/ru/post/224731/


All Articles