Skip to content

Valhalla

Baud Rémy edited this page May 12, 2021 · 1 revision

Valhalla

Valhalla has options to enrich the routing graphs with additional information to enable some of its features:

  • Administrative boundaries
  • Timezones
  • Elevation tiles

Preparations

To build anything with Valhalla you usually need a configuration file first, which also needs to be built.

We recommend using our Valhalla docker image, which you should have already anyways if you want to use this project with Valhalla.

The configuration file needs to be accessed in subsequent steps, so you need to map some (existing) directory into the container:

docker run --rm \
    -v <some_dir>:/data \
    gisops/valhalla:latest \
     bash -c "valhalla_build_config \
    --mjolnir-admin /app/data/valhalla/admins.sqlite \
    --additional-data-elevation /app/data/valhalla/elevation \      
    > /data/valhalla.json"

Now, in <some_dir> you should find the valhalla.json configuration file. You'll reference that in the next steps.

Administrative boundaries

A lot of valuable routing/navigation information is pretty country-specific. Valhalla does an effort to extract and use such data to:

  • avoid country borders
  • enrich the navigation narrative with information such as city, state, country names
  • determine the legal driving side of streets

Find more information in their documentation.

Build

The admin database needs to be built separately as SQLite database to be used during graph generation.

It's best to use the OSM planet for this operation, which will take around 3-4 hours. If you use smaller extracts you risk encountering cropped relations, like country borders, which won't be imported.

It's very important to put the resulting SQLite database in the proper directory: the DATA_DIR/valhalla directory you configured when setting up this project. The name has to be admins.sqlite.

docker run -d --rm\
    -v <some_dir>/valhalla.json:/valhalla.json \
    -v <your_pbf_file>/osm_file.osm.pbf \
    -v <DATA_DIR>/valhalla:/app/data/valhalla
    gisops/valhalla \
    bash -c "valhalla_build_admins -c /valhalla.json /osm_file.osm.pbf"

You should now have the admins.sqlite database in DATA_DIR/valhalla with > 350 MB in size (if you used the full OSM planet).

Timezones

Valhalla also supports the use of timezones, which is important when using time-aware routing (for temporal restrictions, traffic data etc).

Build

The timezone database also needs to be built separately as SQLite database so the graph generation can use it.

It's very important to put the resulting SQLite database in the proper directory: the DATA_DIR/valhalla directory you configured when setting up this project. The name has to be timezones.sqlite.

docker run -d --rm\
    -v <DATA_DIR>/valhalla:/data
    gisops/valhalla \
    bash -c "valhalla_build_timezones > /data/timezones.sqlite"

You should have now the timezones.sqlite database in DATA_DIR/valhalla with around 92 MB in size.

Elevation data

Valhalla can add elevation information to the road network in the graph. It's mostly used for the /height endpoint and to for advances features like use_hills in the biking costing model.

The valhalla_build_elevation command will download the elevation tiles from AWS's open data repository in its custom Skadi format, which is a derivative of the SRTMHGT format. You can read more about the details in TileZen's joerd repository.

Build

The elevation data will be downloaded to a directory you specify. It's very important that it's in the right directory, i.e. DATA_DIR/valhalla/elevation.

You'll also have to specify the bounds for which to download data. The full dataset has 1.6 TeraByte! So do be careful with the bounds.

docker run -d --rm\
    -v <DATA_DIR>/valhalla:/data
    gisops/valhalla \
    bash -c "valhalla_build_elevation <min_x> <max_x> <min_y> <max_y>"
Clone this wiki locally