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.

The initial work on the project was funded by the Department of Transport (DfT) as part of the development of the Propensity to Cycle Tool (PCT). The PCT uses origin-destination data as the basis of spatial analysis and modelling work to identify where bicycle paths are most needed. See the package vignette (e.g. via vignette("introducing-stplanr")) or an academic paper on the Propensity to Cycle Tool (PCT) for more information on how it can be used. This README gives some basics.

stplanr should be useful to researchers everywhere. The function route_graphhopper(), for example, works anywhere in the world using the graphhopper routing API and read_table_builder() reads-in Australian data. We welcome contributions that make transport research easier worldwide.

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:

Let’s take a look at this data:

These datasets can be combined as follows:

The package can also allocate flows to the road network, e.g. with CycleStreets.net and the OpenStreetMap Routing Machine (OSRM) API interfaces. These are supported in route_*() functions such as route_cyclestreets and route_osrm():

Route functions take lat/lon inputs:

trip <-
  route_osrm(from = c(-1, 53), to = c(-1.1, 53))

and place names, found using the Google Map API:

We can replicate this call multiple times using line2route.

intrazone <- travel_network$Area.of.residence == travel_network$Area.of.workplace
travel_network <- travel_network[!intrazone,]
t_routes <- line2route(travel_network, route_fun = route_osrm)
#> Warning in summarise_impl(.data, dots): hybrid evaluation forced for
#> `first`. Please use dplyr::first() or library(dplyr) to remove this
#> warning.

#> Warning in summarise_impl(.data, dots): hybrid evaluation forced for
#> `first`. Please use dplyr::first() or library(dplyr) to remove this
#> warning.
#> Warning in summarise_impl(.data, dots): hybrid evaluation forced for
#> `last`. Please use dplyr::last() or library(dplyr) to remove this warning.

#> Warning in summarise_impl(.data, dots): hybrid evaluation forced for
#> `last`. Please use dplyr::last() or library(dplyr) to remove this warning.
#> Warning in value[[3L]](cond): Fail for line number 18
#> Warning in value[[3L]](cond): Fail for line number 19
#> Warning in value[[3L]](cond): Fail for line number 25
#> Warning in value[[3L]](cond): Fail for line number 26
#> Warning in value[[3L]](cond): Fail for line number 29
#> Warning in value[[3L]](cond): Fail for line number 32
#> Warning in value[[3L]](cond): Fail for line number 33
#> Warning in value[[3L]](cond): Fail for line number 34
#> Warning in value[[3L]](cond): Fail for line number 38
#> Warning in value[[3L]](cond): Fail for line number 39
#> Warning in value[[3L]](cond): Fail for line number 40
#> Warning in value[[3L]](cond): Fail for line number 41
#> Warning in value[[3L]](cond): Fail for line number 42
plot(t_routes)

Another way to visualise this is with the leaflet package:

library(leaflet)
leaflet() %>% addTiles() %>% addPolylines(data = t_routes)

For more examples, example("line2route").

overline is a function which 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 illustrated below.

Installation

To install the stable version, use:

The development version can be installed using devtools:

stplanr depends on rgdal, which can be tricky to install.

Installing stplanr on Linux and Mac

splanr depends on rgdal which can be installed on Ubuntu, for example, with:

sudo apt install r-cran-rgdal

To install gdal binaries on other distributions please see here: http://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries

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

Instructions to install gdal and Quartz are provided at https://github.com/ropensci/geojsonio#install and https://www.xquartz.org/ respectively (Quartz is required for R - as described here).

Funtions, help and contributing

The current list of available functions can be seen with:

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

Meta

  • Please report issues, feature requests and questions to the github issue tracker
  • License: MIT
  • Get citation information for stplanr in R doing citation(package = 'stplanr')
  • This project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.