- Introduction: the Propensity to Cycle Tool
- Packages for transport data
- Where next?
2017-10-09. Slides: rpubs.com/RobinLovelace.
The front page of the open source, open access Propensity to Cycle Tool (PCT).
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)
| 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 |
Robin Lovelace (Lead Developer, University of Leeds)
"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."
"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."
Included in Cycling and Walking Infrastructure Strategy (CWIS) and the Local Cycling and Walking Infrastructure Plan (LCWIP)
Shows on the map where there is high cycling potential, for 4 scenarios of change
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
Provided peer review of the code: https://github.com/ropensci/onboarding/issues/10
Plug Colin's R package courses
Use
@importFromwhenever possible. Right now you haveimport(openxlsx)andimport(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
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'")
}
| 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. |
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
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
flow_single_line = flow[4,] # select only the first line desire_line_single = od2line(flow = flow_single_line, zones = cents)
flow[4,])od2line() matched the cents matching the lines and created a line (the hard bit)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>
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))
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)
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)
library(tmap)
tmap_mode("view")
## tmap mode set to interactive viewing
qtm(cents) + tm_shape(l) + tm_lines(col = "Bicycle", palette = "BuPu", lwd = 5)
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
routes_fast = line2route(l = l)
plot(l) plot(routes_fast, add = T, col = "red")
Credit: Malcolm Morgan
A typology of active travel options.
r.lovelace@leeds.ac.uk or @robinlovelacedevtools::install_github("ropensci/stplanr")
Lovelace, Robin, Anna Goodman, Rachel Aldred, Nikolai Berkoff, Ali Abbas, and James Woodcock. 2017. “The Propensity to Cycle Tool: An Open Source Online System for Sustainable Transport Planning.” Journal of Transport and Land Use 10 (1). doi:10.5198/jtlu.2016.862.