Getting started with OS NGD Transport Path features and pgRouting
Last updated
Website
Ordnance SurveyData
OS Data HubLast updated
The OS National Geographic Database (OS NGD) Transport Theme provides a definitive network dataset and topographic depiction of Great Britain’s roads, railways, tracks and paths. These notes provide an overview of how to create a routable network using the road and path featuers from the NGD Transport Theme with pgRouting. They are only intended to provide guidance and may need to be modified to suit specific use cases and system requirements.
PgRouting is an open-source tool that extends the spatial capabilities of the PostGIS extension to the PostgreSQL database to provide routing functions.
PostgreSQL with the PostGIS and pgRouting extensions (pgRouting is packaged with PostGIS from version 2.1)
OS NGD Transport Network Road Link – network line geometry and attribution describing the link.
OS NGD Transport Network Path Link – network line geometry and attribution describing the link.
OS NGD Transport Network Connecting Link – line segmentation enabling the connection between road and path; it does not represent a real-world feature.
Before beginning you should also consider how much data you need, the bigger the area then the longer it will take to build and perform analysis.
The first step is to download the data from OS DataHub by using OS Select+Build to create a recipe. These are the table names used for this example, you will need to ensure they match or are substituted correctly when replicating.
OS NGD Collection and Feature Type | GeoPackage | Table name | pgRouting |
---|---|---|---|
All OS NGD is available in the GeoPackage format which will be needed to load the data into our PostgreSQL database in order to be prepared for pgRouting. In this example we have created a database schema named ‘pgrouting’ and loaded the data using the DB Manager plugin in QGIS 3.8.1. When loading the data you will need to check the option to Create spatial index as these notes assume the data is indexed.
Before building the network the 3 sets of links need to be combined into 1 layer, ensuring that they all have the same attribution. To keep this simple we have used the minimum attributes required from each. However, these need to be added to the connecting link as described in the following table:
These layers need to be populated, setting the grade separation as 0 and the connecting node and path node values can be used as the end and start node.-- grade separation is set to 0
Once the attribution is populated the 3 layers can be merged into a new layer.
Add a geometry index to the table
These notes are for guidance, table and field names should be checked to ensure they match.
The first statement generates a node lookup using the startNode and endNode references.
Where appropriate, it introduces additional nodes using the grade separation to ensure the real-world physical separations between Links are handled accordingly.
The second statement creates the directed graph which can be used for routing.
It utilises the node lookup to generate the required ‘source’ and ‘target’ integer fields; along with adding 'cost' and 'reverse_cost', these re simply based on length and futher consideration will be needed depending on the types of road in your area. When building a network for vehicle routing you would incorporate one-ways at this point, however as we are creating a walking network these can be ignored.
It also uses the TOID field in the data to create an id for each link, however, to use this as an integer we have stripped OSGB from the start of the value.
This has created a network data set comprising the path data with roads that may have a footpath on either side, using the presence of pavement attribute which is part of the NGD Transport Schema 2 data.
This query calculates how far you can walk in 5 minutes and could be used to identify what facilities are available within walking distance of an address. The first step is to use the network we have created to calculate the walking distance.
The results of this query are presented as a list of roads and paths that are reachable in the time specified. However, you may want to display isochrones for your output and for use in service area analysis. This query takes the output and creates a polygon that represents its boundaries using a concave hull.
Finally, to identify what is within the 15 minutes an intersect query can be used. In this example we are identifying all Community buildings near-by.
The results can then be displayed graphically in a GIS.
https://github.com/mixedbredie/highways-for-pgrouting
https://github.com/tmnnrs/highways-network-pgrouting
PostGreSQL - https://www.postgresql.org/
PostGIS - http://www.postgis.net/
pgRouting - https://pgrouting.org/
OS NGD Transport Network Road Link
trn_ntwk_roadlink
trn_ntwk_roadlink
pgrouting.ngd_roadlink
OS NGD Transport Network Path Link
trn_ntwk_pathlink
trn_ntwk_pathlink
pgrouting.pathlink
OS NGD Transport Network Connecting Link
trn_ntwk_connectinglink
trn_ntwk_connectinglink
pgrouting.connectinglink
endnode
varchar
startnode
varchar
endgradeseparation
Int4
0
startgradeseparation
Int4
0