2017-10-09. Slides: rpubs.com/RobinLovelace.

Outline

  • Introduction: the Propensity to Cycle Tool
  • Packages for transport data
  • Where next?

Introduction

The Propensity to Cycle Tool - see www.pct.bike

The front page of the open source, open access Propensity to Cycle Tool (PCT).

The front page of the open source, open access Propensity to Cycle Tool (PCT).

Context: from concept to implementation

  • 3 years in the making
  • Origins go back further
Concept (PhD) -> Job at UoL (2009 - 2013)
 Discovery of R programming and shiny (2013)
  'Propensity to Cycle' bid by DfT via SDG (2014)
    Link-up with Cambridge University and colleagues (2015)
     Implementation on national OD dataset, 700k routes (2016)
      Completed LSOA phase (4 million lines!) (2017)
  • 2018: (Global PCT?)
  • Now publised in the Journal of Transport and Land Use (JTLU) (Lovelace et al. 2017)

Prior work (source: Lovelace et al. 2017)

Tool Scale Coverage Public access Format of output Levels of analysis Software licence
Propensity to Cycle Tool National England Yes Online map A, OD, R, RN Open source
Prioritization Index City Montreal No GIS-based P, A, R Proprietary
PAT Local Parts of Dublin No GIS-based A, OD, R Proprietary
Usage intensity index City Belo Horizonte No GIS-based A, OD, R, I Proprietary
Bicycle share model National England, Wales No Static A, R Unknown
Cycling Potential Tool City London No Static A, I Unknown
Santa Monica model City Santa Monica No Static P, OD, A Unknown

The PCT team

"If you want to go far, go as a team"

Robin Lovelace (Lead Developer, University of Leeds)

  • James Woodcock (Principal Investigator, Cambridge University)
  • Anna Goodman (Lead Data Analyst, LSHTM)
  • Rachel Aldred (Lead Policy and Practice, Westminster University)
  • Ali Abbas (User Interface, University of Cambridge)
  • Alvaro Ullrich (Data Management, University of Cambridge)
  • Nikolai Berkoff (System Architecture, Independent Developer)
  • Malcolm Morgan (GIS and infrastructure expert, UoL)

Policy feedback

"The PCT is a brilliant example of using Big Data to better plan infrastructure investment. It will allow us to have more confidence that new schemes are built in places and along travel corridors where there is high latent demand."

  • Shane Snow: Head of Seamless Travel Team, Sustainable and Acessible Travel Division

"The PCT shows the country’s great potential to get on their bikes, highlights the areas of highest possible growth and will be a useful innovation for local authorities to get the greatest bang for their buck from cycling investments  and realise cycling potential."

  • Andrew Jones, Parliamentary Under Secretary of State for Transport

The PCT in CWIS and LCWIP

Included in Cycling and Walking Infrastructure Strategy (CWIS) and the Local Cycling and Walking Infrastructure Plan (LCWIP)

How the PCT works

Shows on the map where there is high cycling potential, for 4 scenarios of change

  • Government Target
  • Gender Equality
  • Go Dutch
  • Ebikes

Scenario shift in desire lines

Source: Lovelace et al. (2017)

  • Origin-destination data shows 'desire lines'
  • How will these shift with cycling uptake

Scenario shift in network load

A live demo for Newcastle

"Actions speak louder than words"

Packages for transport data

stplanr

stplanr lives here: https://github.com/ropensci/stplanr

Package can be installed from CRAN or GitHub (see the package's README for details), it can be loaded in with library():

install.packages("stplanr") # stable CRAN version
# devtools::install_github("ropensci/stplanr") # dev version
library(stplanr) # also loads spatial package
## Loading required package: sp
  • Dev version requires rtools on Windows

Hosted at ropensci/stplanr

Example of benefits of peer review

Use @importFrom whenever possible. Right now you have import(openxlsx) and import(sp) in your NAMESPACE file. Just import the functions you need. Same for other pkg deps.

Tests: Pleae write tests to cover at least all the major functions before we accept. Use testthat::skip_on_cran() for any tests that do web requests, so that CRAN tests don't fail in case a service is temporarily down

Addition of better API key handling

I think token's can be a bit easier for the user. Right now you have e.g.,

if (!Sys.getenv('CYCLESTREET') == "") {
    cckey <- Sys.getenv('CYCLESTREET')
}
if(is.null(cckey)){
    stop("You must have a CycleStreets.net api key saved as 'cckey'")
}

Importance of documentation: test datasets

cents SpatialPointsDataFrame.of.home.locations.for.flow.analysis.
destination_zones example destinations data
destinations example destinations data
flow data frame of commuter flows
flow_dests data frame of invented commuter flows with destinations in a different layer than the origins
flowlines SpatialLinesDataFrame of commuter flows
routes_fast SpatialLinesDataFrame of commuter flows on the travel network
routes_slow SpatialLinesDataFrame of commuter flows on the travel network
zones SpatialPolygonsDataFrame of home locations for flow analysis.

Example data: 'Flow' or OD data

data("flow", package = "stplanr")
head(flow[c(1:3, 12)])
##        Area.of.residence Area.of.workplace All Bicycle
## 920573         E02002361         E02002361 109       2
## 920575         E02002361         E02002363  38       0
## 920578         E02002361         E02002367  10       0
## 920582         E02002361         E02002371  44       3
## 920587         E02002361         E02002377  34       0
## 920591         E02002361         E02002382   7       0

Centroids data

data("cents", package = "stplanr")
as.data.frame(cents[1:3,-c(3,4)])
##       geo_code  MSOA11NM coords.x1 coords.x2
## 1708 E02002384 Leeds 055 -1.546463  53.80952
## 1712 E02002382 Leeds 053 -1.511861  53.81161
## 1805 E02002393 Leeds 064 -1.524205  53.80410

Creating a single desire line

flow_single_line = flow[4,] # select only the first line
desire_line_single = od2line(flow = flow_single_line, zones = cents)

What just happened?

  • We selected a single 'od-pair' (flow[4,])
  • The function od2line() matched the cents matching the lines and created a line (the hard bit)
  • How? Check the source code!
od2line
## function(flow, zones, destinations = NULL,
##                     zone_code = names(zones)[1],
##                     origin_code = names(flow)[1],
##                     dest_code = names(flow)[2],
##                     zone_code_d = NA, silent = TRUE) {
##   UseMethod("od2line", object = zones)
## }
## <environment: namespace:stplanr>

A hard-coded version:

o = cents[cents$geo_code %in% flow$Area.of.residence[4],]
d = cents[cents$geo_code %in% flow$Area.of.workplace[4],]
l_single = Lines(list(Line(rbind(o@coords, d@coords))), ID = 1)
l_sp = SpatialLines(LinesList = list(l_single))

Visualising the result

plot(cents)
points(o, cex = 5)
points(d, cex = 5)
flow[4, 1:3]
##        Area.of.residence Area.of.workplace All
## 920582         E02002361         E02002371  44
plot(l_sp, add = TRUE)

Creating 'desire lines' for all flows

l <- od2line(flow = flow, zones = cents)
# remove lines with no length
l <- l[!l$Area.of.residence == l$Area.of.workplace,]
plot(l, lwd = l$All / 10)

Plot the result on an interactive map

library(tmap)
tmap_mode("view")
## tmap mode set to interactive viewing
qtm(cents) + tm_shape(l) +
  tm_lines(col = "Bicycle", palette = "BuPu", lwd = 5)

Allocating flows to the transport network

stplanr has various functions for route allocation:

route_cyclestreet() # UK, cycling
route_graphhopper() # worldwide, any mode
route_transportapi_public() # UK, public transport
viaroute() # worldwide, any mode

Routing many lines

routes_fast = line2route(l = l)
plot(l)
plot(routes_fast, add = T, col = "red")

Future plans

Routing functions

  • Add more services (e.g. OpenTripPlanner)
  • Integrate interface
  • Add support for OSM data download and analysis
  • Via interface to osmdatar

Applications

  • Work with practitioners to make it more useful for them (e.g. ITP)
  • Link with industry (e.g. ITP)
  • Make more international
  • A global propensity to cycle tool?
  • Better handling of GPS data

Where next?

Next steps for the Propensity to Cycle Tool

  • Plans to create a toolkit for cycling infrastructure prioritisation - see cyip.bike
  • Combines many datasets to identify 'low hanging fruit'

Credit: Malcolm Morgan

Potential for cycling - public transport integration

A typology of active travel options.

A typology of active travel options.

Next steps for stplanr

  • Finish paper submitted to the RJournal
  • Transition to sf (1000+ lines of code, 6 month mission underway)
  • Integration with other tools e.g. osmdata and dodgr
  • Improvements to the user interface
  • Feature requests?

Thanks, links, references