Getting started with OS MasterMap Highways Network - Paths and pgRouting
OS MasterMap Highways network is a detailed and accurate network data set for Great Britian. It can be used in a variety of routing applications and these notes help get started with using the data for walk time in the open source application pgRouting.
PgRouting extends the spatial capabilities of the PostGIS extension to the PostgreSQL database to provide routing functions. These notes are based on the work of Tim Manners and Ross MacDonald which has been shared on GitHub and provide an overview of how to create a network data set for use with pgRouting.
Software Requirements
PostgreSQL with the PostGIS and pgRouting extensions (pgRouting is packaged with PostGIS from version 2.1)
Data Requirements
OS MasterMap Highways Road and Asset Management Information (RAMI) – this gives the additional features required for routing although it is possible to build a basic network without these
Tables required:
Base data
RoadLink – network line geometry and attribution describing the link.
PathLink – network line geometry and attribution describing the link.
ConnectingLink – line segmentation enabling the connection between road and path; it does not represent a real world feature.
Depending on how the data has been translated from the GML this may be one table for each of these or separate tables for the different elements of each. The instructions work best if you have separated the network references into separate tables.
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.
Preparing the data
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. As the default value for Formofway is set to ‘Connecting link’ this should already be populated.
Once the attribution is populated the 3 layers can be merged into a new layer.
Add a geometry index to the table
Building the network
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 RoadLinks 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 further 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.
Enhancing the network
The example creates a network which is suitable for use for basic walking routes. However, it assumes that all add roads have a footpath alongside them. It reality we know what Motorways and other trunk roads will not have a footpath and we may also want to use local knowledge to exclude certain roads from the next week. Consideration should also be given to the type of user avoiding features such as steps.
This can be done by either deleting features from the data, this would work for Motorways, or by giving links we want to avoid a negative value, so they are excluded from any analysis. The following example uses OS MasterMap Topography Layer features to identify where a road has a man-made roadside as an indication of a footpath. This will also include other features such as traffic islands and roundabout. As traffic islands can be used as a possible crossing point we have left this as part of the network however in the example have excluded any link where formofway equals roundabout.
As we only want to change the costs of using the roads the first step is to change these to a negative cost.
Now we are going to use the OS MasterMap Topography Layer to assign a cost to all roads that have a path alongside them.
This has created a network data set comprising the path data with roads that may have a footpath on either side.
Example usage of pgRouting
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.
Create a Polygon Isochrone for your results
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.
Points within the isochrone
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.
Further information
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/
Last updated