![](/style/images/good.png)
![](/style/images/bad.png)
Deploying OSMR
source link: https://willschenk.com/howto/2024/deploying_osmr/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
I'm working on a routing service, and been playing around with different projects based off of the OpenStreetMap project.
Here's what I went through to deploy the OpenSourceRoutingMachine project locally.
docker volume create map_data
We'll startup a container that has that volume mounted it in, and then download the data from the internet and process it as needed.
Prepare the data
docker run -it --rm -v map_data:/data ghcr.io/project-osrm/osrm-backend bash
https://download.geofabrik.de/ has a lot of files available that we
can use to import, lets find an .osm.pbf
file, say something at
https://download.geofabrik.de/north-america.html
Inside of the container:
FILE=north-america
# FILE=connecticut
apt-get update && apt-get install -y wget
cd /data
wget https://download.geofabrik.de/${FILE}-latest.osm.pbf
That file is 14G fyi, and takes about 15m just to download on my connection!
Then extract:
osrm-extract -p /opt/car.lua /data/${FILE}-latest.osm.pbf || echo "osrm-extract failed"
osrm-partition /data/${FILE}-latest.osrm || echo "osrm-partition failed"
osrm-customize /data/${FILE}-latest.osrm || echo "osrm-customize failed"
And you can quit out of that container.
Run the server
docker run -it \
-p 5000:5000 \
-v map_data:/data \
ghcr.io/project-osrm/osrm-backend osrm-routed \
--algorithm mld \
/data/north-america-latest.osrm
Once that gets going, we can hit it locally and pass the results
through jq
:
curl "http://127.0.0.1:5000/route/v1/driving/-73.364755,41.838942;-73.409656,41.752237?steps=true" \
| jq -r '.routes | .[] | .legs | .[] | .steps | .[] | .name'
Popple Swamp Road River Road South Kent Road South Warren Hill Road Cornwall Road Kent Road Segar Mountain Road Kenico Road Gorham Road Old Homestead Lane Stonewall Lane
CLI Testing
There's also a library that makes better words out of the responses.
npm i osrm-text-instructions
Quick formatting demo:
var version = 'v5';
var osrmTextInstructions = require('osrm-text-instructions')(version);
fetch(
"http://127.0.0.1:5000/route/v1/driving/-73.364755,41.838942;-73.409656,41.752237?steps=true" )
.then( (response) => response.json() )
.then( (response) => {
response.routes[0].legs.forEach(function(leg) {
leg.steps.forEach(function(step) {
instruction = osrmTextInstructions.compile('en', step)
console.log( instruction )
});
})
})
Which gives us:
Head southwest on Popple Swamp Road
Turn right onto River Road South
Go straight onto Kent Road South (US 7)
Make a slight left onto Warren Hill Road (CT 45)
Continue onto Cornwall Road (CT 45)
Turn right onto Kent Road (CT 341)
Continue onto Segar Mountain Road (CT 341)
Turn right onto Kenico Road
Continue slightly left onto Gorham Road
Turn right onto Old Homestead Lane
Continue left onto Stonewall Lane
Turn right
You have arrived at your destination, on the right
Starting a front end
It does come with a front end, but I think Leaflet is more promising as a start.
docker run -p 9966:9966 osrm/osrm-frontend
xdg-open 'http://127.0.0.1:9966'
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK