Host your own version of a map for free
This is a tutorial on how to use OSRM to host a local version of your map so as to query it as opposed to querying the readily available services on the internet like google maps, mapbox, routific, etc.
Each has its own weaknesses and strengths, the strength points of OSRM are speed, freedom to manipulate the map data and zero costs.
First we need to download the map data,
The bigger the area, the more time it will take to extract the map data and the more RAM it will occupy when hosted, and this thing is hungry for RِAM.
We can extract and host it on a server which we will discuss later,
We can download the compressed daily updated map data which can be found on https://download.geofabrik.de/ , download the osm.pbf file which is a compressed file, you can also click on any of the regions, like Europe or wherever you want, to get a sub region and download it.
Or you can also use https://extract.bbbike.org/ , which can be a bit behind on updates and maybe doesn't have all the data, to cut the area that you want then download it and don't forget to donate to those guys, they have saved you a lot, as extracting the map can cost you a sum of money, if you don't have the resources and need to rent a server to extract it.
Or you can also use https://extract.bbbike.org/ , which can be a bit behind on updates and maybe doesn't have all the data, to cut the area that you want then download it and don't forget to donate to those guys, they have saved you a lot, as extracting the map can cost you a sum of money, if you don't have the resources and need to rent a server to extract it.
Next we need osrm's backend,
To use it, we either can compile it or use a readily available docker container,
i always use a docker container as compiling osrm can be quite a headache.
i always use a docker container as compiling osrm can be quite a headache.
Installing docker on linux is quite easy,
I used to work on debian but now i use ubuntu as it has more readily available packages since it has a wider base of users.
For ubuntu, you can follow the guide here https://docs.docker.com/install/linux/docker-ce/ubuntu/
I used to work on debian but now i use ubuntu as it has more readily available packages since it has a wider base of users.
For ubuntu, you can follow the guide here https://docs.docker.com/install/linux/docker-ce/ubuntu/
For windows,
you will have to install the docker toolbox first Following this guide here https://docs.docker.com/toolbox/toolbox_install_windows/
you will have to install the docker toolbox first Following this guide here https://docs.docker.com/toolbox/toolbox_install_windows/
After downloading the pbf file, create a folder wherever you like and put the .pbf file inside, it will be just used to hold the other files extracted from it.
Start a terminal,
Navigate into the folder,
Navigate into the folder,
Execute docker pull osrm/osrm-backend to pull the osrm-backend docker container that we will use to extract and host the map data
and navigate to the directory,
Then execute to preprocess the file with the car profile docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/filename.osm.pbf
Be sure to replace filename with the filename of your pbf file.
There are other profiles, please check here to know more https://github.com/Project-OSRM/osrm-backendIf it fails with an error message profile /opt/car.lua not found, then try
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p ../osrm-backend/profiles/car.lua /data/filename.osm.pbf
Next do docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/filename.osrm
Next execute docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/filename.osrm
Next execute docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/filename.osrm
It should display a message running and waiting for requests , to make sure its exposed, Start your favourite browser and navigate to http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true
You should get a json response
Next is the frontend, you can use
osrm/osrm-frontend https://github.com/Project-OSRM/osrm-frontend
Personally i prefer Leaflet https://leafletjs.com/
The reason why i prefer leaflet is that i can use it for my route optimization algorithms.
You can download the latest version of leaflet (currently 3.2.12) from here https://github.com/perliedman/leaflet-routing-machine/releases
After extracting the zip file, you can try any of the html files in the examples folder.
Comments
Post a Comment