stplanr

Sustainable transport planning with R

https://github.com/ropensci/stplanr

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    7 of 35 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.9%) to scientific vocabulary

Keywords

cycle cycling desire-lines origin-destination peer-reviewed pubic-transport r r-package route-network routes routing rstats spatial transport transport-planning transportation walking

Keywords from Contributors

geo gdal genome book distance rspatial mock street-networks geocoder visualisation
Last synced: 6 months ago · JSON representation

Repository

Sustainable transport planning with R

Basic Info
Statistics
  • Stars: 429
  • Watchers: 20
  • Forks: 67
  • Open Issues: 25
  • Releases: 45
Topics
cycle cycling desire-lines origin-destination peer-reviewed pubic-transport r r-package route-network routes routing rstats spatial transport transport-planning transportation walking
Created about 11 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---




```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# stplanr 


[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/stplanr)](https://github.com/r-hub/cranlogs.app)
[![](https://cranlogs.r-pkg.org/badges/grand-total/stplanr)](https://cran.r-project.org/package=stplanr)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/stplanr)](https://cran.r-project.org/package=stplanr)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![](https://badges.ropensci.org/10_status.svg)](https://github.com/ropensci/software-review/issues/10)
[![R-CMD-check](https://github.com/ropensci/stplanr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/stplanr/actions/workflows/R-CMD-check.yaml)

```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(stplanr)
```

**stplanr** is a package for sustainable transport planning with R.

It provides functions for solving common problems in transport planning and modelling, such as how to best get from point A to point B.
The overall aim is to provide a reproducible, transparent and accessible toolkit to help people better understand transport systems and inform policy, as outlined in a [paper](https://journal.r-project.org/archive/2018/RJ-2018-053/index.html) about the package, and the potential for open source software in transport planning in general, published in the [R Journal](https://journal.r-project.org/).

The initial work on the project was funded by the Department of Transport
([DfT](https://www.gov.uk/government/organisations/department-for-transport))
as part of the development of the Propensity to Cycle Tool
(PCT), a web application to explore current travel patterns and cycling potential at zone, desire line, route and route network levels (see [www.pct.bike](https://www.pct.bike/) and click on a region to try it out).
The basis of the methods underlying the PCT is origin-destination data, which are used to highlight where many short distance trips are being made, and estimate how many could switch to cycling.
The results help identify where cycleways are most needed, an important component of sustainable transport planning infrastructure engineering and policy design.

See the package vignette (e.g. via `vignette("introducing-stplanr")`) 
or an [academic paper on the Propensity to Cycle Tool (PCT)](https://dx.doi.org/10.5198/jtlu.2016.862)
for more information on how it can be used.
This README provides some basics.

Much of the work supports research undertaken at the Leeds' Institute for Transport Studies ([ITS](https://environment.leeds.ac.uk/transport)) but  **stplanr** should be useful to transport researchers and practitioners needing free, open and reproducible methods for working with geographic data everywhere.

## Key functions

Data frames representing flows between origins and destinations
must be combined with geo-referenced zones or points to generate meaningful
analyses and visualisations of 'flows' or origin-destination (OD) data.
**stplanr** facilitates this with
`od2line()`, which takes flow and geographical data as inputs and
outputs spatial data. Some example data is provided in the package:

```{r, results='hide', message=FALSE}
library(stplanr)
```

Let's take a look at this data:

```{r}
od_data_sample[1:3, 1:3] # typical form of flow data
cents_sf[1:3,] # points representing origins and destinations
```

These datasets can be combined as follows:

```{r plot1, warning=FALSE}
travel_network <- od2line(flow = od_data_sample, zones = cents_sf)
w <- flow$all / max(flow$all) *10
plot(travel_network, lwd = w)
```


**stplanr** has many functions for working with OD data.
See the [`stplanr-od`](https://docs.ropensci.org/stplanr/articles/stplanr-od.html) vignette for details.

The package can also allocate flows to the road network, e.g. with [CycleStreets.net](https://www.cyclestreets.net/api/) and the OpenStreetMap Routing Machine ([OSRM](https://github.com/Project-OSRM/osrm-backend)) API interfaces.
These are supported in `route_*()` functions such as `route_cyclestreets` and `route_osrm()`:

Routing can be done using a range of back-ends and using lat/lon or desire line inputs with the `route()` function, as illustrated by the following commands which calculates the route between Fleet Street and Southwark Street over the River Thames on Blackfriars Bridge in London:

```{r, eval=FALSE, echo=FALSE}
tmaptools::geocode_OSM("fleet street london")
tmaptools::geocode_OSM("southwark street london")
```


```{r}
library(osrm)
trip <- route(
  from = c(-0.11, 51.514),
  to = c(-0.10, 51.506),
  route_fun = osrmRoute,
  returnclass = "sf"
  )
plot(trip)
```

You can also use and place names, found using the Google Map API:

```{r cycle-trip, message=FALSE, warning=FALSE, eval=FALSE, echo=FALSE}
if(!Sys.getenv("CYCLESTREETS") == ""){
  trip <- route_cyclestreets("Bradford, UK", "Leeds, Yorkshire", plan = "balanced")
  plot(trip)
}
```

```{r}
trip2 <- route(
  from = "Leeds",
  to = "Bradford",
  route_fun = osrmRoute,
  returnclass = "sf"
  )
plot(trip2)
```

We can replicate this call multiple times with the `l` argument in `route()`:

```{r}
desire_lines <- travel_network[2:6, ]
```

```{r, echo=FALSE}
# Sys.sleep(2) # wait a moment 
```


Next, we'll calculate the routes:

```{r plot2, results='hide', message=FALSE}
routes <- route(
  l = desire_lines,
  route_fun = osrmRoute,
  returnclass = "sf"
  )
plot(sf::st_geometry(routes))
plot(desire_lines, col = "red", add = TRUE)
```



```{r routes, echo=FALSE, eval=FALSE}
lwd <- desire_lines$foot
routes <- routes_fast_sf[2:6, ]
plot(routes$geometry, lwd = lwd)
plot(desire_lines$geometry, col = "green", lwd = lwd, add = TRUE)
```

For more examples, `example("route")`.

`overline()` takes a series of route-allocated lines,
splits them into unique segments and aggregates
the values of overlapping lines. This can represent where there will be
most traffic on the transport system, as demonstrated in the following code chunk. 

```{r rnet, warning=FALSE}
routes$foot <- desire_lines$foot
rnet <- overline(routes, attrib = "foot")
```

The resulting route network, with segment totals calculated from overlapping parts for the routes for walking, can be visualised as follows:

```{r}
plot(rnet["foot"], lwd = rnet$foot)
```

The above plot represents the number walking trips made (the 'flow') along particular segments of a transport network.



```{r, routes-leaf, eval=FALSE, echo=FALSE}
library(leaflet)
pal = leaflet::colorNumeric(palette = "YlGnBu", domain = rnet$all)
leaflet(data = rnet) %>%
  addProviderTiles(providers$OpenStreetMap.BlackAndWhite) %>%
  addPolylines(weight = rnet$all / 3, color = ~pal(all), opacity = 0.9) %>% 
  addLegend(pal = pal, values = ~all)
```

## Policy applications

The examples shown above, based on tiny demonstration datasets, may not seem particularly revolutionary.
At the city scale, however, this type of analysis can be used to inform sustainable transport policies, as described in papers [describing the Propensity to Cycle Tool](https://www.jtlu.org/index.php/jtlu/article/view/862/859) (PCT), and its [application to calculate cycling to school potential](https://doi.org/10.1016/j.jth.2019.01.008) across England.

Results generated by **stplanr** are now part of national government policy: the PCT is the recommended tool for local and regional authorities developing strategic cycle network under the Cycling and Walking Infrastructure Strategy ([CWIS](https://www.gov.uk/government/publications/cycling-and-walking-investment-strategy)), which is part of the Infrastructure Act [2015](https://www.legislation.gov.uk/ukpga/2015/7/contents/enacted).
**stplanr** is helping dozens of local authorities across the UK to answer the question: where to prioritise investment in cycling?
In essence, stplanr was designed to support sustainable transport policies.

There are many other research and policy questions that functions in **stplanr**, and other open source software libraries and packages, can help answer.
At a time of climate, health and social crises, it is important that technology is not only sustainable itself (e.g. as enabled by open source communities and licenses) but that it contributes to a sustainable future.

## Installation

To install the stable version, use:

```{r, eval=FALSE}
install.packages("stplanr")
```

The development version can be installed using **devtools**:

```{r, eval=FALSE}
# install.packages("devtools") # if not already installed
devtools::install_github("ropensci/stplanr")
library(stplanr)
```

### Installing stplanr on Linux and Mac

**stplanr** depends on **sf**. Installation instructions for Mac, Ubuntu and other Linux distros can be found here: https://github.com/r-spatial/sf#installing

## Funtions, help and contributing

The current list of available functions can be seen on the package's website at [docs.ropensci.org/stplanr/](https://docs.ropensci.org/stplanr/), or with the following command:

```{r, eval=FALSE}
lsf.str("package:stplanr", all = TRUE)
```

To get internal help on a specific function, use the standard way.

```{r, eval=FALSE}
?od2line
```

To contribute, report bugs or request features, see the [issue tracker](https://github.com/ropensci/stplanr/issues).

```{r, eval=FALSE, echo=FALSE}
# Aim: explore dependencies
desc = read.dcf("DESCRIPTION")
headings = dimnames(desc)[[2]]
fields = which(headings %in% c("Depends", "Imports", "Suggests"))
pkgs = paste(desc[fields], collapse = ", ")
pkgs = gsub("\n", " ", pkgs)
strsplit(pkgs, ",")[[1]]
install.packages("miniCRAN")
library(miniCRAN)
tags <- "stplanr"
pkgDep(tags)
dg <- makeDepGraph(tags, enhances = TRUE)
set.seed(1)
plot(dg, legendPosition = c(-1, 1), vertex.size = 20)
library(DiagrammeR)
DiagrammeR::visnetwork(dg)
visNetwork::visIgraph(dg)
```

## Further resources / tutorials

Want to learn how to use open source software for reproducible sustainable 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 of *Geocomputation with R*, which provides a broad introduction from a geographic data perspective: https://r.geocompx.org/transport.html
- The **stplanr** paper, which describes the context in which the package was developed: https://journal.r-project.org/archive/2018/RJ-2018-053/index.html (please cite this if you use **stplanr** in your work)
- The `dodgr` vignette, which provides an introduction to routing in R: https://github.com/UrbanAnalyst/dodgr

## Meta

* Please report issues, feature requests and questions to the [github issue tracker](https://github.com/ropensci/stplanr/issues)
* License: MIT
* Get citation information for **stplanr** in R doing `citation(package = 'stplanr')`
* This project is released with a [Contributor Code of Conduct](https://github.com/ropensci/stplanr/blob/master/CONDUCT.md).
By participating in this project you agree to abide by its terms.

[![rofooter](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)

Owner

  • Name: rOpenSci
  • Login: ropensci
  • Kind: organization
  • Email: info@ropensci.org
  • Location: Berkeley, CA

GitHub Events

Total
  • Create event: 3
  • Release event: 1
  • Issues event: 18
  • Watch event: 11
  • Issue comment event: 35
  • Push event: 8
  • Pull request review event: 1
  • Pull request event: 2
  • Fork event: 2
Last Year
  • Create event: 3
  • Release event: 1
  • Issues event: 18
  • Watch event: 11
  • Issue comment event: 35
  • Push event: 8
  • Pull request review event: 1
  • Pull request event: 2
  • Fork event: 2

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 1,844
  • Total Committers: 35
  • Avg Commits per committer: 52.686
  • Development Distribution Score (DDS): 0.16
Past Year
  • Commits: 45
  • Committers: 3
  • Avg Commits per committer: 15.0
  • Development Distribution Score (DDS): 0.067
Top Committers
Name Email Commits
Robin Lovelace r****x@g****m 1,549
Richard Ellison r****n@i****u 136
Malcolm Morgan m****8 40
mpadge m****m@e****m 19
Andrea a****3@g****m 15
Nikolai B n****b 14
Andrea Gilardi a****5@c****t 11
wangzhao0217 w****7@g****m 9
Karthik Ram k****m@g****m 7
Layik Hama l****a@g****m 4
Maëlle Salmon m****n@y****e 4
mvl22 m****n@l****k 3
steven2249 s****w@b****u 3
RFlx 3****a 2
Josiah Parry j****y@g****m 2
Edzer Pebesma e****a@u****e 2
Scott Chamberlain m****s@g****m 2
ilanfri i****i@m****m 2
usr110 m****s@g****m 2
jn t****i@g****m 2
Matthew Petersen m****n@g****m 2
seanolondon S****l@l****k 1
Malcolm Morgan m****2@h****m 1
Nick Bearman n****n@g****m 1
meptrsn m****w@m****o 1
timpearson99 t****n@c****k 1
unknown r****e@F****u 1
virgesmith a****h@l****k 1
munterfinger l****n@h****h 1
hxd1011 h****1@g****m 1
and 5 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 271
  • Total pull requests: 291
  • Average time to close issues: 5 months
  • Average time to close pull requests: 7 days
  • Total issue authors: 55
  • Total pull request authors: 27
  • Average comments per issue: 4.3
  • Average comments per pull request: 1.38
  • Merged pull requests: 263
  • Bot issues: 0
  • Bot pull requests: 1
Past Year
  • Issues: 7
  • Pull requests: 2
  • Average time to close issues: about 14 hours
  • Average time to close pull requests: about 6 hours
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 4.86
  • Average comments per pull request: 2.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Robinlovelace (171)
  • agila5 (8)
  • mem48 (7)
  • wangzhao0217 (6)
  • sckott (5)
  • rsbivand (5)
  • maelle (5)
  • mpadge (3)
  • mvl22 (3)
  • joeytalbot (3)
  • JimShady (3)
  • richardellison (3)
  • meptrsn (2)
  • nikolai-b (2)
  • yairlevy (2)
Pull Request Authors
  • Robinlovelace (161)
  • richardellison (64)
  • mpadge (11)
  • mem48 (8)
  • wangzhao0217 (6)
  • agila5 (6)
  • maelle (5)
  • nikolai-b (5)
  • karthik (2)
  • meptrsn (2)
  • Nowosad (2)
  • sckott (2)
  • temospena (2)
  • edzer (2)
  • JosiahParry (2)
Top Labels
Issue Labels
help wanted (7) enhancement (6) bug (4) good first issue (4) ro-hackathon-2025 (3) Needs documentation (1)
Pull Request Labels
dependencies (1)

Packages

  • Total packages: 2
  • Total downloads:
    • cran 1,616 last-month
  • Total docker downloads: 89,487
  • Total dependent packages: 3
    (may contain duplicates)
  • Total dependent repositories: 8
    (may contain duplicates)
  • Total versions: 63
  • Total maintainers: 1
cran.r-project.org: stplanr

Sustainable Transport Planning

  • Versions: 53
  • Dependent Packages: 3
  • Dependent Repositories: 8
  • Downloads: 1,616 Last month
  • Docker Downloads: 89,487
Rankings
Docker downloads count: 0.0%
Stargazers count: 0.9%
Forks count: 1.0%
Average: 5.4%
Downloads: 9.2%
Dependent repos count: 10.6%
Dependent packages count: 10.6%
Maintainers (1)
Last synced: 6 months ago
proxy.golang.org: github.com/ropensci/stplanr
  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago

Dependencies

docs/articles/introducing-stplanr_files/leaflet-providers-1.0.27/bower.json bower
  • leaflet ~0.7.3
DESCRIPTION cran
  • R >= 3.5.0 depends
  • Rcpp >= 0.12.1 imports
  • curl >= 3.2 imports
  • data.table * imports
  • dplyr >= 0.7.6 imports
  • httr >= 1.3.1 imports
  • jsonlite >= 1.5 imports
  • lwgeom >= 0.1.4 imports
  • magrittr * imports
  • methods * imports
  • nabor >= 0.5.0 imports
  • od * imports
  • pbapply * imports
  • rlang >= 0.2.2 imports
  • sf >= 0.6.3 imports
  • sfheaders * imports
  • cyclestreets * suggests
  • dodgr >= 0.2.15 suggests
  • geodist * suggests
  • igraph >= 1.2.2 suggests
  • knitr >= 1.20 suggests
  • leaflet * suggests
  • mapsapi * suggests
  • opentripplanner * suggests
  • osrm * suggests
  • pct * suggests
  • rmarkdown >= 1.10 suggests
  • testthat >= 2.0.0 suggests
  • tmap * suggests
docs/articles/introducing-stplanr_files/leaflet-providers-1.0.27/package.json npm
  • chai ^2.3.0 development
  • eslint ^2.7.0 development
  • eslint-plugin-html ^1.4.0 development
  • mocha ^2.2.4 development
  • mocha-phantomjs ^3.5.3 development
  • mversion ^2.0.0 development
  • phantomjs 1.9.7-15 development
  • uglify-js ^2.4.15 development
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v1 composite
  • actions/checkout master composite
  • r-lib/actions/pr-fetch master composite
  • r-lib/actions/pr-push master composite
  • r-lib/actions/setup-r master composite