Instructions to get you started with using OS MRN in OpenTripPlanner.
OpenTripPlanner (OTP) is an open source multi-modal trip planner, focussing on travel by scheduled public transportation in combination with bicycling, walking, and mobility services, including bike share and ride hailing.
Java Virtual Machine (JVM) (Java 17+)
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'.
In terms of creating a transit network using OS MRN, you'll require the following files (ensure that they are stored in the same directory):
The otp-2.5.0-shaded.jar
"shaded" JAR (Java ARchive) containing OTP and all other libraries needed for it to work.
Some General Transit Feed Specification (GTFS) data for Transit Schedules and Stops, for example, Bus Open Data Service (BODS).
OS MRN Protocolbuffer Binary Format (PBF) data downloaded from the OS Data Hub (OSMulti-modalRoutingNetwork.pbf
).
The General Transit Feed Specification (GTFS) is an Open Standard used to distribute relevant information about transit systems to riders. It allows public transit agencies to publish their transit data in a format that can be consumed by a wide variety of software applications.
The Bus Open Data Service (BODS) provides bus timetable, vehicle location and fares data for every local bus service in England.
The OpenTripPlanner Basic Tutorial provides a detailed set on instructions of how to get the interactive OTP instance up-and-running, but fundamentally the steps are as follows:
Open PowerShell / Command Prompt (Windows) or Shell (Linux) and navigate to the folder where the OTP JAR, BODS GTFS, and OS MRN PBF files have been stored.
Run the following command to start the service: java -Xmx8G -jar otp-2.5.0-shaded.jar --build --serve . --port 8801
.
Go to http://localhost:8801/ in a web browser.
Instructions to get you started with using OS MRN in pgRouting.
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide routing and other network analysis functionality.
QGIS provides a few useful options for pgRouting and the handling of OS MRN data:
Part of the QGIS install gives access to a command prompt that comes with some spatial functionality for data management without needing much setup (this will be covered in more detail below).
It can be linked in with the PostgreSQL database to allow for visualising existing tables and pgRouting results.
It gives access to pgRouting in plugin form, allowing routes to be calculated within QGIS using those database tables.
A graph data structure is made up of nodes and edges. With OS MRN, these are represented by the mrn_ntwk_transportnode
and mrn_ntwk_transportlink
layers.
Nodes are points that represent junctions connecting one or more paths on a network. This is where a decision is made on where to turn next (or stop if you are at the end of the route). All nodes must connect to an edge.
Edges connect two or more nodes, and represent the distance between them. They can be directed (for example, one-way restrictions) or undirected (any direction allowed). Their default direction will be in the direction the edge was digitised, from startpoint to endpoint.
The distance is a reflection of the cost to travel along that edge. At the base level, this would be the length of the edge (in metres), but can be extended with maths to incorporate things like the speed of travel along the edge.
Using other data you may have, cost can be extended even further, for example, to take into account factors that might make a traveller use a particular route more (such as scenery, traffic, points of interest and gradient).
With pgRouting, these costs can be applied to each edge in a particular direction, that is, in direction (the direction of digitising) and in reverse direction. This enables the user to have more control on what the routing algorithms look for.
Routing algorithms are a set of rules used to determine the best path between two or more points. Some of the common ones used are:
pgr_dijkstra
– The classic shortest path algorithm, from one node to another, using a directed or non-directed graph.
pgr_drivingdistance
– Using Dijkstra, finds all nodes that are reachable within a set distance using a directed or non-directed graph. Produces results that can then be visualised as an isochrone polygon.
pgr_trsp
(turn restriction shortest path) – Runs similar to Dijkstra, with the addition of using restriction information. With OS MRN, this restriction data is available in the mrn_ntwk_turnrestriction
layer. These turn restrictions reference the edges from the network layer and are used as a lookup as the algorithm works.
In more recent versions of PostgreSQL, both PostGIS and pgRouting are enabled as standard, ready to be used.
To check this:
Load pgAdmin4 (or your chosen database explorer).
Highlight your database.
Open a SQL window and run:
In the example above, PostGIS was already enabled. However, in the example below, pgRouting wasn't enabled, but is now ready to be used within the selected database:
The easiest way to load the GeoPackage (GPKG) into PostgreSQL via ogr2ogr is to use the OSGeo4W Shell that is provided with the QGIS install package:
Before loading the GPKG, check that environment variables have been set up so that PostgreSQL will be recognised by the command prompt. Admin permissions are required to edit these variables.
Add the folder location of your PostgreSQL install to the User->Path
and System->Path
variables.
Once you have done this, open the OSGeo4W Shell (as shown above), and type in ogr2ogr
.
If everything is setup correctly, you should see:
To then load the OS MRN GPKG into your PostgreSQL database, navigate to the location of the file, and type the following:
You could alternatively use the following command (where /vsizip/
is a file handler that allows reading ZIP archives on-the-fly without decompressing them beforehand):
This will load the three layers of the OS MRN GPKG into the defined database schema, and create the relevant spatial indexes.
You can now add some further attribute indexes for the unique identifiers:
With all the indexes added, you can create a basic edge table on which to start routing:
osm2po is a cross platform tool written in Java that can be used to parse OS MRN PBF data and make it routable in pgRouting.
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] from https://adoptium.net/en-GB/.
Once osm2po is downloaded and extracted, open and edit the config file to satisfy your usage requirements (for example, change the wtr.finalMask = car
line (use Ctrl+F to search the file) to car,foot,bike
travel types).
Uncomment the following line (this helps with getting the topology into a format pgRouting likes):
When this is done, and assuming Java is installed and accessible, open a command prompt and navigate to the location of the .pbf file, and then run the following:
This will create the .sql file version of the .pbf file.
Import the .sql file version of the .pbf file to the PostgreSQL database using the following:
In this newly created table, each record should have a source and target node, and an integer classification. Cost and reverse cost columns are also applied. Cost in this case is worked out using distance (in km) and speed (kmh) defined in the config file.
The mandatory things pgRouting needs to be able to route with are a routing table, start node and end node. Once the routing table is created, pgRouting can be run straight away.
For the following example, OS MRN sample data has been used, with the GPKG data being loaded into PostgreSQL via ogr2ogr (with the SQL run to create basic edge table). A couple of waypoints have been selected in Exeter, and a sample Dijkstra route query can look like the one below:
This route query is made up of three parts:
First, the 'start' section finds the start node to use from the network that is closest to the point given. This could be fed in to the query in multiple ways, such as clicking on a web map, or using a plugin.
Second, the 'destination' section finds the start node closest to the destination point given.
The final part includes the pgr_dijkstra
function, reading in the start and destination ids, and returns a merged geometry of links that form the route.
When visualised in QGIS, the result should look similar to this:
It should be noted that the above route query does not take any of the additional OS MRN attribution into account. This means that every edge will be considered when calculating the shortest path. We can therefore apply some additional logic in the SELECT
statement to facilitate either vehicular or pedestrian routing:
Vehicular routing – Determines the best vehicular route where the edges are deemed to be roads.
Pedestrian routing – Determines where the edges can be traversed by foot and whether there is designated infrastructure for walking.
A lot of routing software used in the OpenStreetMap (OSM) project supports Protocolbuffer Binary Format (PBF). There are several tools to convert from PBF to OSM XML and vice versa, if required, including Osmconvert, Osmosis and Osmium:
OSM files are usually sorted in a specific way: first the nodes ordered by ID, then ways ordered by ID, then relations ordered by ID. But this is not necessarily always the case.
It is important to check if a file is sorted correctly as many commands only work properly if a file is sorted.
To check if a file is sorted, in use fileinfo
:
To sort a file using :
To sort a file using :
This getting started guide provides instructions for using OS MRN in different routing software applications. Users with limited technical knowledge will be able to follow this guide.
OS Multi-modal Routing Network (OS MRN) is designed for use in routing applications. Numerous different routing software applications are available.
This guide includes instructions to get you started with using OS MRN in three open-source routing applications:
– for GeoPackage (GPKG) and Protocolbuffer Binary Format (PBF)
– for PBF
– for PBF
The guide also has a page on , where you will find guidance on:
The ability to carry out multi-modal routing is dependent on the software you use. To make full use of the functionality of OS MRN, you may need to make configuration changes to your software, for example, configuring it to use the speed data or time conditional attributes. It is also possible to use third party datasets, such as bus and train timetables, with OS MRN to enhance multi-modal routing.
OS MRN data can be downloaded from the (for further guidance, please see ).
Instructions to get you started with using OS MRN in GraphHopper.
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:
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.
Tool
Description
Functionality
Example
Lightweight (but fast) application to convert and process OSM files.
Basic
osmconvert OSMulti-modalRoutingNetwork.pbf >OSMulti-modalRoutingNetwork.osm
Command-line application for processing OSM data.
Intermediate
osmosis --read-pbf OSMulti-modalRoutingNetwork.pbf --write-xml OSMulti-modalRoutingNetwork.osm
Multipurpose command-line tool based on the Osmium Library.
Advanced
osmium cat OSMulti-modalRoutingNetwork.pbf -o OSMulti-modalRoutingNetwork.osm