Basic routing with OS Open Data and QGIS

Drivetime analysis

Drivetime analysis is a tool used to determine which locations are accessible from a point within a certain time or distance based on a road network.

Road Networks

Ordnance Survey has a number of road network products of different levels of detail:

Product
Complexity
Availability
Description

OS MasterMap Highways Network – Roads

High Complexity

Premium

A topologically structured link and node representation of GB's road network

OS MasterMap Highways Network – Routing and Asset Management (RAMI)

Most Complex

Premium

The content of Roads with additional information on the management of roads as an asset and routing information

OS Open Roads

Lower Complexity

Open

An open high-level view of GB's road network

OS NGD Transport Network

High Complexity

Available under the PSGA

The OS NGD equivalent of our topological road network

OS NGD Routing and Asset Management

High Complexity

Available under the PSGA

The OS NGD equivalent of our additional RAMI data

Multi-modal Routing Network

Most Complex

Available under the PSGA

New data for integrated routing between road, rail, pedestrian, etc.

OS Open Roads

We will use OS Open Roads for the road network drive time analysis.

OS Open Roads is our free, high-level road network dataset and is our simplest representation of Great Britain’s roads.

Processing

  • Download OS Open Roads from the OS Data Hub.

  • Select the GeoPackage file format for this analysis

  • Extract the GPKG file and load into QGIS.

  • Open Roads contains three feature types: Motorway Junction, RoadLink and RoadNode

Optional - To reduce the processing time of the next steps consider either clipping the road_link layer to your area of interest (AOI) once you have downloaded the data or selecting the links for the area you want and then right-click on the layer -> Export -> Save Selected Features As and then you will have a dataset for just the area you need.

Adding Simple Road Speeds

  • In QGIS, right click on the road_link layer and select 'Toggle Editing'

  • Right click on the road_link layer and click to open the Attribute Table (This may take a while to open)​

  • Click on Open Field Calculator to add a column for the speed data​

  • Check Create a new field

  • Input speed_kph to name new field

  • Copy and paste the below code into the expression tab

CASE 
WHEN "road_classification" = 'A Road' THEN 56
WHEN "road_classification" = 'B Road' THEN 48
WHEN "road_classification" = 'Motorway' THEN 112
else 32 END

Routing

QGIS has a built in Network Analysis tools such as service area and shortest path. However, for a visually clearer output we will be using a plugin called QNEAT3

Select the QNEAT3 Toolbox from the toolbox panel and select Iso-Area as Polygons

Fill in the pop up box as shown here:

Visualising the output

In the Layer Properties window under the Symbology tab:

  • Select 'Categorized'

  • In the value field select '1.2 cost_level

  • Select a suitable Color ramp

  • Change the fill for 'all other values' to transparent

Add a base map of your choice, we have used the OS Maps API Light style here:

Drive times shown over the OS Maps API Light style

Determining shortest routes to an end point

Using the road_link data that we have already prepared we can do some different routing analysis. Now we need some start points to represent our addresses and an end point to be our school or store. If you already have these great, or we can create the points ourselves in QGIS. For a tutorial in how to create a vector layer in QGIS please follow this link:

https://docs.qgis.org/3.40/en/docs/training_manual/create_vector_data/create_new_vector.html

Create about 15 start points and 1 end point and situate these near to the road_link network. Once you have saved these add the start and end points to your map:

Start and end points depicted in QGIS

Now we can start to do our analysis in determining the shortest routes. Again, we will use QNEAT3 for a clearer output.

Open the Processing toolbox > open QNEAT3 > click on the arrow next to Distance Matrices and select OD Matrix from Layers as Lines (m:n):

As we have a column that contains speed in km/h we can calculate the routes to our end point in terms of either distance or time.

Calculating routes based on distance

To calculate the shortest routes based on distance to our OSHO endpoint, double click on OD Matrix from Layers as Lines (m:n). This pop-up window will appear, fill it in as suggested:

  1. Select the road_link data as our Network Layer

  2. Select our multiple addresses as our start point as the From-Point Layer

  3. Select our destination end point (in this case OSHO) as our To-Point Layer

  4. Choose Shortest Path (distance optimization) from Optimization Criterion

  5. Choose Matrix Geometry follows routes (otherwise we will just have straight lines from the addresses to the OSHO end point)

  6. Leave the Speed Field [optional] blank

  7. Select an output folder destination

  8. Click Run!

This will take a minute or so to run but you will end up with routes from your addresses to your end point.

Routes depicted from start to end points in QGIS

Visualising the output

The routes can be styled according to their distance to OSHO, in this case using a green (shortest) to red (longest) style.

In the Layer Properties window under the Symbology tab:

  1. Select 'Categorized'

  2. In the value field select ‘total_cost’

  3. Select a suitable Color ramp

  4. Change the fill for 'all other values' to transparent

The address point routes in the image above have also been labelled according to their id so that they can be visually cross referenced to the attribute table.

The attribute table shows the total_cost column which in this case is the distance in metres from the address point to the end point.

For information, the entry_cost is an estimated calculation which considers distance to get to a car, distance to the road etc. The exit_cost is distance from road to destination; disembarkation time if you will.

Calculating routes based on time

To calculate the shortest routes based on time to our OSHO endpoint, double click on OD Matrix from Layers as Lines (m:n) again. This time fill in the pop-up window as below:

  1. Select the road_link data as our Network Layer

  2. Select our multiple addresses as our start point as the From-Point Layer

  3. Select our destination end point (in this case OSHO) as our To-Point Layer

  4. Choose Fastest Path (time optimization) from Optimization Criterion

  5. Choose Matrix Geometry follows routes (otherwise we will just have straight lines from the addresses to the OSHO end point)

  6. Select speed_kmh from the Speed field [optional] drop down

  7. Select an output folder destination

  8. Click Run!

Again, this will take a minute or so to run and this time the routes will have a total cost that represents travel time, not distance.

QNEAT3 calculates the time by analysing each link and the speed in km/h associated with and applies this equation to calculate that time taken in seconds to travel a particular route:

((length/1000)/speed_kph)*3600[EB1]

Again, the routes can be styled depending on their time; green being the quickest through to red being the slowest.

The address point routes have again been labelled according to their id so that they can be cross referenced to the attribute table.

The attribute table this time shows the total_cost column which in this case is the time taken in seconds to get from each address point to the OSHO end point. The entry_cost and exit_cost will also be in seconds.

In this exercise we have only used one end point and multiple start points but this QNEAT3 algorithm can process multiple start and end points. The m:n in brackets after the OD Matrix from Layers as Lines (m:n) indicates that this is the case and refers to the relationship between the start (origin) and end (destination) points.

m = the number of origin points; and

n = the number of destination points.

So, m:n means that the OD Matrix from Layers as Lines (m:n) function will calculate routes from every origin point to every destination point, in other words a full origin-destination matrix.

Therefore, if you have: 5 origin points (m =5); and

3 destination points (n=5)

OD Matrix from Layers as Lines (m:n) will calculate 15 routes, one for each origin-destination pair.

Benefits

  • Simple drivetime analysis

  • All open-source data and software

  • Visualisation of distribution and hard to access areas

  • Overview of how accessible your services are

  • Identify areas for more detailed study

Last updated

Was this helpful?