GraphHopper
Instructions to get you started with using OS MRN in GraphHopper.
Last updated
Instructions to get you started with using OS MRN in GraphHopper.
Last updated
is an open source routing engine for OpenStreetMap (OSM).
(Java 17+)
and
To find out if you have Java installed:
Open PowerShell / Command Prompt (Windows) or Shell (Linux) and type:
Press Enter.
If Java is installed, you should see a few lines of text detailing which version you have installed. If you get something along the lines of "java is not recognized ..."
please download JVM [or OpenJDK] using the link above in 'What you need'.
To see if you already have Node.js and npm installed and check the installed version:
Run the following commands:
If they are not installed, please follow the .
The explains how to download and run the GraphHopper Routing Engine as a Java library or standalone web server to calculate the distance, time, turn-by-turn instructions and many road attributes for a route between two or more points.
To create routes using OS MRN, you require the following files (ensure that they are stored in the same directory):
A YAML configuration file (config-example.yml
)
We have created a custom version of this file which allows for vehicular (car) routing with turn costs, as well as the calculation of pedestrian (walking) and cycling routes:
Compared to the basic configuration file, you'll see that the custom version enables turn restrictions (under the car profile) and includes additional profiles to enable cycling and walking:
Notes:
The turn_costs
line tells GraphHopper to force the car
travel mode ("profile") to respect turn restrictions.
The u_turn_costs
line tells GraphHopper how long a U-turn should add to your route (in this case, 60 seconds).
The custom_model_files
are required but can be empty. The optional bike.json
is a reference to a specification to get cycle routing to prefer less busy roads, for example.
By default (i.e. only using driving routing), GraphHopper knows there's no need to read in footpaths, cycleways, etc. Now that you want the additional "profiles", you need to change that.
This means that there is one final configuration change you need to do which will force GraphHopper to read every type of link:
Use Ctrl+F to search the config-example-multiple.yml
file for:
You can now start the GraphHopper Maps UI and the web service as follows:
This reads in the OS MRN data and sets everything up. It might take a few minutes the first time you run this command, but when complete, you will see two folders have been added to your directory: "graph-cache" and "logs".
When you start GraphHopper again, it will see the data contained within the "graph-cache" folder and know that it doesn't have to re-read the PBF file. However, if you update your .pbf or .yml files, make sure you delete "graph-cache" before starting GraphHopper again.
Right-click on the map to create a route.
The JAR (Java ARchive) package file containing the GraphHopper Maps UI and the web service
OS MRN Protocolbuffer Binary Format (PBF) data downloaded from the (OSMulti-modalRoutingNetwork.pbf
)
The provided in the aforementioned GraphHopper repository enables basic vehicular (car) routing.
Once you see a 'Server - Started'
log message, go to and you'll see an interactive map of your chosen location.
The supplements the GraphHopper Routing Engine as a customisable version of the route planner user interface. This repository contains instructions on how to start development and how to make configuration changes, including adding different map tile providers. You can add , or if you like.
You will also be able to point to the web service hosted at .
To ease getting up-and-running, we have taken a fork of the above repository and made the necessary to add in the OS Maps API Outdoor, Light and Road styles. You can clone the forked repository from the .
All you need to then do is add a valid API Key (with a suitable ) to the file.