Skip to content

Instantly share code, notes, and snippets.

@jbelien
Last active May 23, 2018 13:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbelien/84273bf8dcf9038b0a2cd7ef2cb80142 to your computer and use it in GitHub Desktop.
Save jbelien/84273bf8dcf9038b0a2cd7ef2cb80142 to your computer and use it in GitHub Desktop.
Itinero Routing API

Ubuntu 16.04

Install .NET core

https://www.microsoft.com/net/core#linuxubuntu

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'

sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.0

Install IDP

https://github.com/itinero/idp

git clone https://github.com/itinero/idp.git
cd ./idp
sh build.sh
sh publish.sh

Generate .routerdb file

Belgium

wget http://download.geofabrik.de/europe/belgium-latest.osm.pbf

Pedestrian profile

./src/IDP/bin/release/netcoreapp2.0/ubuntu.16.04-x64/IDP \
    --read-pbf belgium-latest.osm.pbf --pr \
    --create-routerdb vehicles=pedestrian \
    --contract pedestrian \
    --write-routerdb belgium.p.routerdb

or

./src/IDP/bin/release/netcoreapp2.0/ubuntu.16.04-x64/IDP \
    --read-pbf belgium-latest.osm.pbf --pr \
    --create-routerdb vehicles=pedestrian \
    --write-routerdb belgium.p.routerdb

./src/IDP/bin/release/netcoreapp2.0/ubuntu.16.04-x64/IDP \
    --read-routerdb belgium.p.routerdb --pr \
    --contract pedestrian \
    --write-routerdb belgium.p.cf.routerdb

If you need shortest profile, just add --contract pedestrian.shortest !

Car and Pedestrian profiles

./src/IDP/bin/release/netcoreapp2.0/ubuntu.16.04-x64/IDP \
    --read-pbf ../belgium-latest.osm.pbf --pr \
    --create-routerdb vehicles=car,pedestrian \
    --contract car --contract pedestrian
    --write-routerdb belgium.cp.cf.routerdb

.cp is for car + pedestrian profiles
.cf is for fastest contraction

Custom profile

If you want to use a custom profile, replace car or pedestrian default profile by the path to the .lua file :

./src/IDP/bin/release/netcoreapp2.0/ubuntu.16.04-x64/IDP \
    --read-pbf ../belgium-latest.osm.pbf --pr \
    --create-routerdb vehicles=car,./profiles/osm/pedestrian.lua \
    --contract car --contract pedestrian
    --write-routerdb belgium.cp.cf.routerdb

Install Routing API

git clone https://github.com/itinero/routing-api.git
cd ./routing-api
sh build.sh

Copy the .routerdb file(s) must be in the ./routing-api/src/Itinero.API/data directory !

Configure Routing API as a Background Service

http://supervisord.org/

sudo apt-get install supervisor

Edit supervisord.conf

sudo vim /etc/supervisor/supervisord.conf

Change chmod from 700 to 766.

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0766                      ; socket file mode (default 0700)

Create configuration file for Routing API

sudo vim /etc/supervisor/conf.d/routing-api.conf

Add following content :

[group:routing]
programs=routing

[program:routing]
directory=/home/ubuntu/routing-api/src/Itinero.API
command=/usr/bin/dotnet ./bin/Debug/netcoreapp2.0/Itinero.API.dll
autostart=true
autorestart=true
stderr_logfile=/var/log/routing.err.log
stdout_logfile=/var/log/routing.out.log
user=ubuntu
stopsignal=INT
stopasgroup=true

Restart supervisor

sudo service supervisor restart

Start Routing API Background Service

supervisorctl start routing:

Host Routing API behind Apache

https://httpd.apache.org/

sudo apt install apache2

Enable mod_proxy_http

sudo a2enmod proxy_http

Edit 000-default.conf

sudo vim /etc/apache2/sites-available/000-default.conf

Add following content :

ProxyPass "/"  "http://localhost:5000/"
ProxyPassReverse "/"  "http://localhost:5000/"

Restart apache2

sudo service apache2 restart

Enjoy !

Everything should now work ; you can use the API by connecting to http://<yourIPAddress>/ !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment