- Notifications
You must be signed in to change notification settings - Fork30
A brief example to combine OSRM with Express (NodeJs)
License
door2door-io/osrm-express-server-demo
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A brief example to combine OSRM with Express (NodeJs) to build your ownproduction-ready instance.
It is based onOpen Source Routing Machine (OSRM)andExpress.
In order to run this application you need to installDocker:
- Mac OSX via homebrew:
brew cask install docker - others:https://docs.docker.com/engine/installation/
If the installation is successful, you should be able to run the following commandand get a similar response:
docker version# output:Client: Version: 17.07.0-ce-rc1 API version: 1.31 Go version: go1.8.3 Git commit: 8c4be39 Built: Wed Jul 26 05:20:09 2017 OS/Arch: darwin/amd64Server: Version: 17.07.0-ce-rc1 API version: 1.31 (minimum version 1.12) Go version: go1.8.3 Git commit: 8c4be39 Built: Wed Jul 26 05:25:01 2017 OS/Arch: linux/amd64 Experimental: true- the main application:
docker build -t osrm-express-server -f Dockerfile.nodejs . - osmium-tool for data manipulation:
docker build -t osmium-tool -f Dockerfile.osmium-tool . - osrm-backend to generate the routable graph:
docker pull osrm/osrm-backend:v5.22.0
In order to run this application a routable graph generated by OSRM is required.OSRM itself can build a graph from various sources, in the following OpenStreetMap (OSM)data is used.
Download the region you are interested in (e.g. Europe) fromGeofabrik or similarsources and save the result in the folderdata/
curl --create-dirs --output data/osrm/example-areas/europe-latest.osm.pbf http://download.geofabrik.de/europe-latest.osm.pbfIf your preferred region is not available, you can take a larger dataset and clip it to specific areas.The following will use theeurope-latest.osm.pbf dataset, extract Berlin and London and save it as a newdataset.
We can now make use of the previously containerisedosmium-tool to extract specific areas with a.poly file.Read more about Poly-fileshere:
docker run -it -v $(pwd)/data:/data osmium-tool extract -p /data/polyfiles/example-areas.poly /data/osrm/example-areas/europe-latest.osm.pbf -o /data/osrm/example-areas/example-areas.osm.pbfOnce we have our dataset, we can pass it to the OSRM container to create a routable graph with a given profile (car, foot, bike, ...)with the contraction hierachies algorithm:
# extract the network and create the osrm file(s)docker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.16.1 osrm-extract -p /opt/car.lua /data/osrm/example-areas/example-areas.osm.pbf# create the graphdocker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.16.1 osrm-contract /data/osrm/example-areas/example-areas.osrmThe dataset is now available at./data/osrm/example-areas and can be used by any OSRM instance running the same version.
In order to launch the application with the specified dataset (see above), runthe container with the required environment variables, port mapping and volume bindings:
docker run --env-file .env -d -p 5000:5000 -v $(pwd)/data:/data osrm-express-serverThe.env file is a (modified) copy of the.env.example file contained in this repository.Please adapt it according to your needs.
Also please make sure to map the correct volumes (host and container) as well as the ports inorder to access the server.
After the application has loaded the graph in memory, you can make requests to the server running athttp://localhost:5000
This example application has 3 different endpoints
GET /health: A simple ping endpoint to check that the server is running.POST /route: Implements calls toosrm.routeto calculate the way from A to B.Example body:
{ coordinates: [[13.3905, 52.5205], [13.3906, 52.5206]] }POST /table: Implements calls toosrm.tableto get a travel times matrix for all provided locations.Example body:
{ coordinates: [[13.3905, 52.5205], [13.3906, 52.5206]] }
The source code should be simple enough to provide an overview and to get started forextensions / own development.
This repository also includes a small and simple test suite.In order to run the tests in the container, execute the following commands:
docker run -it --env-file .env -v $(pwd)/data:/data -p 5000:5000 osrm-express-server yarn lintdocker run -it --env-file .env -v $(pwd)/data:/data -p 5000:5000 osrm-express-server yarn testThe test graph is a small subsample of areas in Berlin and London and is included in this repository.Whenever you upgrade to a newer OSRM version, you need to rebuild the test graph as well to successfully run the tests again:
docker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.22.0 osrm-extract -p /opt/car.lua /data/osrm/test/test.osm.pbfdocker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.22.0 osrm-partition /data/osrm/test/test.osm.pbfdocker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.22.0 osrm-customize /data/osrm/test/test.osm.pbfAbout
A brief example to combine OSRM with Express (NodeJs)
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.