- Notifications
You must be signed in to change notification settings - Fork66
Sustainable transport planning with R
License
ropensci/stplanr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
stplanr is a package for sustainable transport planning with R.
It provides functions for solving common problems in transport planningand modelling, such as how to best get from point A to point B. Theoverall aim is to provide a reproducible, transparent and accessibletoolkit to help people better understand transport systems and informpolicy, as outlined in apaperabout the package, and the potential for open source software intransport planning in general, published in theRJournal.
The initial work on the project was funded by the Department ofTransport(DfT)as part of the development of the Propensity to Cycle Tool (PCT), a webapplication to explore current travel patterns and cycling potential atzone, desire line, route and route network levels (seewww.pct.bike and click on a region to try itout). The basis of the methods underlying the PCT is origin-destinationdata, which are used to highlight where many short distance trips arebeing made, and estimate how many could switch to cycling. The resultshelp identify where cycleways are most needed, an important component ofsustainable transport planning infrastructure engineering and policydesign.
See the package vignette (e.g. viavignette("introducing-stplanr")
) oranacademic paper on the Propensity to Cycle Tool(PCT) for more information onhow it can be used. This README provides some basics.
Much of the work supports research undertaken at the Leeds’ Institutefor Transport Studies (ITS)butstplanr should be useful to transport researchers andpractitioners needing free, open and reproducible methods for workingwith geographic data everywhere.
Data frames representing flows between origins and destinations must becombined with geo-referenced zones or points to generate meaningfulanalyses and visualisations of ‘flows’ or origin-destination (OD) data.stplanr facilitates this withod2line()
, which takes flow andgeographical data as inputs and outputs spatial data. Some example datais provided in the package:
library(stplanr)
Let’s take a look at this data:
od_data_sample[1:3,1:3]# typical form of flow data#> # A tibble: 3 × 3#> geo_code1 geo_code2 all#> <chr> <chr> <dbl>#> 1 E02002361 E02002361 109#> 2 E02002361 E02002363 38#> 3 E02002361 E02002367 10cents_sf[1:3,]# points representing origins and destinations#> geo_code MSOA11NM percent_fem avslope geometry#> 1708 E02002384 Leeds 055 0.458721 2.856563 -1.546463, 53.809517#> 1712 E02002382 Leeds 053 0.438144 2.284782 -1.511861, 53.811611#> 1805 E02002393 Leeds 064 0.408759 2.361707 -1.524205, 53.804098
These datasets can be combined as follows:
travel_network<- od2line(flow=od_data_sample,zones=cents_sf)w<-flow$all/ max(flow$all)*10plot(travel_network,lwd=w)
stplanr has many functions for working with OD data. See thestplanr-od
vignette for details.
The package can also allocate flows to the road network, e.g. withCycleStreets.net and theOpenStreetMap Routing Machine(OSRM) API interfaces.These are supported inroute_*()
functions such asroute_cyclestreets
androute_osrm()
:
Routing can be done using a range of back-ends and using lat/lon ordesire line inputs with theroute()
function, as illustrated by thefollowing commands which calculates the route between Fleet Street andSouthwark Street over the River Thames on Blackfriars Bridge in London:
library(osrm)#> Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright#> Routing: OSRM - http://project-osrm.org/trip<- route(from= c(-0.11,51.514),to= c(-0.10,51.506),route_fun=osrmRoute,returnclass="sf" )#> Warning: "returnclass" is deprecated.#> Most common output is sfplot(trip)
You can also use and place names, found using the Google Map API:
trip2<- route(from="Leeds",to="Bradford",route_fun=osrmRoute,returnclass="sf" )#> Warning: "returnclass" is deprecated.#> Most common output is sfplot(trip2)
We can replicate this call multiple times with thel
argument inroute()
:
desire_lines<-travel_network[2:6, ]
Next, we’ll calculate the routes:
routes<- route(l=desire_lines,route_fun=osrmRoute,returnclass="sf" )#> Warning: "returnclass" is deprecated.#> Warning: "returnclass" is deprecated.#> Warning: "returnclass" is deprecated.#> Warning: "returnclass" is deprecated.#> Warning: "returnclass" is deprecated.plot(sf::st_geometry(routes))plot(desire_lines,col="red",add=TRUE)#> Warning in plot.sf(desire_lines, col = "red", add = TRUE): ignoring all but the#> first attribute
For more examples,example("route")
.
overline()
takes a series of route-allocated lines, splits them intounique segments and aggregates the values of overlapping lines. This canrepresent where there will be most traffic on the transport system, asdemonstrated in the following code chunk.
routes$foot<-desire_lines$footrnet<- overline(routes,attrib="foot")
The resulting route network, with segment totals calculated fromoverlapping parts for the routes for walking, can be visualised asfollows:
plot(rnet["foot"],lwd=rnet$foot)
The above plot represents the number walking trips made (the ‘flow’)along particular segments of a transport network.
The examples shown above, based on tiny demonstration datasets, may notseem particularly revolutionary. At the city scale, however, this typeof analysis can be used to inform sustainable transport policies, asdescribed in papersdescribing the Propensity to CycleTool (PCT),and itsapplication to calculate cycling to schoolpotential across England.
Results generated bystplanr are now part of national governmentpolicy: the PCT is the recommended tool for local and regionalauthorities developing strategic cycle network under the Cycling andWalking Infrastructure Strategy(CWIS),which is part of the Infrastructure Act2015.stplanr is helping dozens of local authorities across the UK toanswer the question: where to prioritise investment in cycling? Inessence, stplanr was designed to support sustainable transport policies.
There are many other research and policy questions that functions instplanr, and other open source software libraries and packages, canhelp answer. At a time of climate, health and social crises, it isimportant that technology is not only sustainable itself (e.g. asenabled by open source communities and licenses) but that it contributesto a sustainable future.
To install the stable version, use:
install.packages("stplanr")
The development version can be installed usingdevtools:
# install.packages("devtools") # if not already installeddevtools::install_github("ropensci/stplanr")library(stplanr)
stplanr depends onsf. Installation instructions for Mac, Ubuntuand other Linux distros can be found here:https://github.com/r-spatial/sf#installing
The current list of available functions can be seen on the package’swebsite atdocs.ropensci.org/stplanr/, orwith the following command:
lsf.str("package:stplanr",all=TRUE)
To get internal help on a specific function, use the standard way.
?od2line
To contribute, report bugs or request features, see theissuetracker.
Want to learn how to use open source software for reproduciblesustainable transport planning work? Now is a great time to learn.Transport planning is a relatively new field of application in R.However, there are already some good resources on the topic, including(any further suggestions: welcome):
- The Transport chapter ofGeocomputation with R, which provides abroad introduction from a geographic data perspective:https://r.geocompx.org/transport.html
- Thestplanr paper, which describes the context in which thepackage was developed:https://journal.r-project.org/archive/2018/RJ-2018-053/index.html(please cite this if you usestplanr in your work)
- The
dodgr
vignette, which provides an introduction to routing in R:https://github.com/UrbanAnalyst/dodgr
- Please report issues, feature requests and questions to thegithubissue tracker
- License: MIT
- Get citation information forstplanr in R doing
citation(package = 'stplanr')
- This project is released with aContributor Code ofConduct.By participating in this project you agree to abide by its terms.
About
Sustainable transport planning with R