12.5 Routes

From a geographer’s perspective, routes are desire lines that are no longer straight:the origin and destination points are the same, but the pathway to get from A to B is more complex.Desire lines contain only two vertices (their beginning and end points) but routes can contain hundreds of vertices if they cover a large distance or represent travel patterns on an intricate road network (routes on simple grid-based road networks require relatively few vertices).Routes are generated from desire lines — or more commonly origin-destination pairs — using routing services which either run locally or remotely.

Local routing can be advantageous in terms of speed of execution and control over the weighting profile for different modes of transport.Disadvantages include the difficulty of representing complex networks locally; temporal dynamics (primarily due to traffic); and the need for specialized software such as ‘pgRouting’, an issue that developers of packages stplanr and dodgr seek to address.

Remote routing services, by contrast, use a web API to send queries about origins and destinations and return results generated on a powerful server running specialised software.This gives remote routing services various advantages, including that they usually:

  • Update regularly.
  • Have global coverage.
  • Run on specialist hardware and software set-up for the job.
    Disadvantages of remote routing services include speed (they rely on data transfer over the internet) and price (the Google routing API, for example, limits the number of free queries).The googleway package provides an interface to Google’s routing API.Free (but rate limited) routing service include OSRM and openrouteservice.org.

Instead of routing all desire lines generated in the previous section, which would be time and memory-consuming, we will focus on the desire lines of policy interest.The benefits of cycling trips are greatest when they replace car trips.Clearly, not all car trips can realistically be replaced by cycling.However, 5 km Euclidean distance (or around 6-8 km of route distance) can realistically be cycled by many people, especially if they are riding an electric bicycle (‘ebike’).We will therefore only route desire lines along which a high (300+) number of car trips take place that are up to 5 km in distance.This routing is done by the stplanr function line2route() which takes straight lines in Spatial or sf objects, and returns ‘bendy’ lines representing routes on the transport network in the same class as the input.

  1. desire_lines$distance = as.numeric(st_length(desire_lines))
  2. desire_carshort = dplyr::filter(desire_lines, car_driver > 300 & distance < 5000)
  1. route_carshort = line2route(desire_carshort, route_fun = route_osrm)

st_length() determines the length of a linestring, and falls into the distance relations category (see also Section 4.2.6).Subsequently, we apply a simple attribute filter operation (see Section 3.2.1) before letting the OSRM service do the routing on a remote server.Note that the routing only works with a working internet connection.

We could keep the new route_carshort object separate from the straight line representation of the same trip in desire_carshort but, from a data management perspective, it makes more sense to combine them: they represent the same trip.The new route dataset contains distance (referring to route distance this time) and duration fields (in seconds) which could be useful.However, for the purposes of this chapter, we are only interested in the geometry, from which route distance can be calculated.The following command makes use of the ability of simple features objects to contain multiple geographic columns:

  1. desire_carshort$geom_car = st_geometry(route_carshort)

This allows plotting the desire lines along which many short car journeys take place alongside likely routes traveled by cars by referring to each geometry column separately (desire_carshort$geometry and desire_carshort$geom_car in this case).Making the width of the routes proportional to the number of car journeys that could potentially be replaced provides an effective way to prioritize interventions on the road network (Lovelace et al. 2017).

Plotting the results on an interactive map, with mapview::mapview(desire_carshort$geom_car) for example, shows that many short car trips take place in and around Bradley Stoke.It is easy to find explanations for the area’s high level of car dependency: according to Wikipedia, Bradley Stoke is “Europe’s largest new town built with private investment”, suggesting limited public transport provision.Furthermore, the town is surrounded by large (cycling unfriendly) road structures, “such as junctions on both the M4 and M5 motorways” (Tallon 2007).

There are many benefits of converting travel desire lines into likely routes of travel from a policy perspective, primary among them the ability to understand what it is about the surrounding environment that makes people travel by a particular mode.We discuss future directions of research building on the routes in Section 12.9.For the purposes of this case study, suffice to say that the roads along which these short car journeys travel should be prioritized for investigation to understand how they can be made more conducive to sustainable transport modes.One option would be to add new public transport nodes to the network.Such nodes are described in the next section.