Building on the work of previous posts looking at building routable networks and finding the shortest path in a network, this post will look at creating buffers around nodes based on a cost attribute specifed by the user.
The driving distance function, which comes with pg routing 2.0, creates an alpha shape around a node, normally based on the distance someone could travel from that node, or how far someone could go in a time interval.
For this example, we are looking at where someone could travel in 1km along the network from a central node. The following query selects all the nodes that are within 1 km of node 2000.
Once a routable network has been set up we can start to find the shortest path (using Dijkstra’s algorithm) between two points. From here on, I will be using the OSM data for the London road network.
The query use’s a ‘cost’ column – which could be anything thing you like – to calculate the shortest cost from one node to another. In this example I decided to use travel time (rather than distance).
First, I changed the distance of each vertex (the way table) from km to miles, and then calculated the time it would take to traverse each vertex whether walking, cycling or driving. To make this more accurate, I updated the max speed (forward and backward) along each vertex dependent on its class (as listed in the class table).
An earlier post looked at how to extract shapefile data from Open Street Map.
This is very useful for collecting data that is not provided easily in the public realm, although caution must be taken when deciding if the data is complete. One case where I needed a shapefile for a project, and I was very certain that set would be complete, is that of open spaces in London.
This was achieved by searching the features database and locating any key:value pairs of interest. These were the following:
- Landuse: Cemetery, clearing, conservation, forest, garden, grass, meadow, nature reserve, park, recreation ground, recreational, sport, village green and wood.
- Leisure: Sports centre, golf course, common, pitch and playground
- Natural: Grass, grassland and woodland
This was probably a few too many features, so some were removed after a comparison with OSM to see what I had and had not captured.
Also, from these selections, I decided to create two layers; an open space (everything that does not require payment/membership to enter) and green spaces (everything). Furthermore, I separated these into open access and private access by searching for the tags access=yes and access=private in the ‘other’ field of the shapefile.