{"id":13398214,"url":"https://github.com/ropensci/stplanr","last_synced_at":"2025-05-14T13:03:12.256Z","repository":{"id":26608402,"uuid":"30063520","full_name":"ropensci/stplanr","owner":"ropensci","description":"Sustainable transport planning with R","archived":false,"fork":false,"pushed_at":"2025-04-28T10:38:23.000Z","size":26892,"stargazers_count":428,"open_issues_count":24,"forks_count":68,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-03T17:03:52.895Z","etag":null,"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"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/stplanr","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-01-30T08:34:49.000Z","updated_at":"2025-05-01T07:59:31.000Z","dependencies_parsed_at":"2023-09-21T19:43:14.753Z","dependency_job_id":"d3c51ea5-2cda-4709-ab8f-68b57b7c40fb","html_url":"https://github.com/ropensci/stplanr","commit_stats":{"total_commits":1837,"total_committers":34,"mean_commits":"54.029411764705884","dds":"0.15895481763745234","last_synced_commit":"295ec8e0aeae14761c89047d4ff11f2f990dcff3"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstplanr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstplanr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstplanr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Fstplanr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/stplanr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252372175,"owners_count":21737476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"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"],"created_at":"2024-07-30T19:00:20.393Z","updated_at":"2025-05-14T13:03:12.173Z","avatar_url":"https://github.com/ropensci.png","language":"R","funding_links":[],"categories":["Uncategorized","Consumption","R","Energy Consumption"],"sub_categories":["Uncategorized","Mobility and Transportation"],"readme":"---\noutput: github_document\n---\n\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# stplanr \u003ca href='https://docs.ropensci.org/stplanr/'\u003e\u003cimg src='man/figures/logo.png' align=\"right\" height=215/\u003e\u003c/a\u003e\n\n\u003c!-- [![Build Status](https://travis-ci.org/ropensci/stplanr.svg?branch=master)](https://travis-ci.org/ropensci/stplanr) --\u003e\n[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/stplanr)](https://github.com/r-hub/cranlogs.app)\n[![](https://cranlogs.r-pkg.org/badges/grand-total/stplanr)](https://cran.r-project.org/package=stplanr)\n[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/stplanr)](https://cran.r-project.org/package=stplanr)\n[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)\n[![](https://badges.ropensci.org/10_status.svg)](https://github.com/ropensci/software-review/issues/10)\n[![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)\n\n```{r, echo=FALSE, message=FALSE, warning=FALSE}\nlibrary(stplanr)\n```\n\n**stplanr** is a package for sustainable transport planning with R.\n\nIt provides functions for solving common problems in transport planning and modelling, such as how to best get from point A to point B.\nThe 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/).\n\nThe initial work on the project was funded by the Department of Transport\n([DfT](https://www.gov.uk/government/organisations/department-for-transport))\nas part of the development of the Propensity to Cycle Tool\n(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).\nThe 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.\nThe results help identify where cycleways are most needed, an important component of sustainable transport planning infrastructure engineering and policy design.\n\nSee the package vignette (e.g. via `vignette(\"introducing-stplanr\")`) \nor an [academic paper on the Propensity to Cycle Tool (PCT)](https://dx.doi.org/10.5198/jtlu.2016.862)\nfor more information on how it can be used.\nThis README provides some basics.\n\nMuch 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.\n\n## Key functions\n\nData frames representing flows between origins and destinations\nmust be combined with geo-referenced zones or points to generate meaningful\nanalyses and visualisations of 'flows' or origin-destination (OD) data.\n**stplanr** facilitates this with\n`od2line()`, which takes flow and geographical data as inputs and\noutputs spatial data. Some example data is provided in the package:\n\n```{r, results='hide', message=FALSE}\nlibrary(stplanr)\n```\n\nLet's take a look at this data:\n\n```{r}\nod_data_sample[1:3, 1:3] # typical form of flow data\ncents_sf[1:3,] # points representing origins and destinations\n```\n\nThese datasets can be combined as follows:\n\n```{r plot1, warning=FALSE}\ntravel_network \u003c- od2line(flow = od_data_sample, zones = cents_sf)\nw \u003c- flow$all / max(flow$all) *10\nplot(travel_network, lwd = w)\n```\n\n\n**stplanr** has many functions for working with OD data.\nSee the [`stplanr-od`](https://docs.ropensci.org/stplanr/articles/stplanr-od.html) vignette for details.\n\nThe 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.\nThese are supported in `route_*()` functions such as `route_cyclestreets` and `route_osrm()`:\n\nRouting 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:\n\n```{r, eval=FALSE, echo=FALSE}\ntmaptools::geocode_OSM(\"fleet street london\")\ntmaptools::geocode_OSM(\"southwark street london\")\n```\n\n\n```{r}\nlibrary(osrm)\ntrip \u003c- route(\n  from = c(-0.11, 51.514),\n  to = c(-0.10, 51.506),\n  route_fun = osrmRoute,\n  returnclass = \"sf\"\n  )\nplot(trip)\n```\n\nYou can also use and place names, found using the Google Map API:\n\n```{r cycle-trip, message=FALSE, warning=FALSE, eval=FALSE, echo=FALSE}\nif(!Sys.getenv(\"CYCLESTREETS\") == \"\"){\n  trip \u003c- route_cyclestreets(\"Bradford, UK\", \"Leeds, Yorkshire\", plan = \"balanced\")\n  plot(trip)\n}\n```\n\n```{r}\ntrip2 \u003c- route(\n  from = \"Leeds\",\n  to = \"Bradford\",\n  route_fun = osrmRoute,\n  returnclass = \"sf\"\n  )\nplot(trip2)\n```\n\nWe can replicate this call multiple times with the `l` argument in `route()`:\n\n```{r}\ndesire_lines \u003c- travel_network[2:6, ]\n```\n\n```{r, echo=FALSE}\n# Sys.sleep(2) # wait a moment \n```\n\n\nNext, we'll calculate the routes:\n\n```{r plot2, results='hide', message=FALSE}\nroutes \u003c- route(\n  l = desire_lines,\n  route_fun = osrmRoute,\n  returnclass = \"sf\"\n  )\nplot(sf::st_geometry(routes))\nplot(desire_lines, col = \"red\", add = TRUE)\n```\n\n\u003c!-- The resulting routes will look something like this: --\u003e\n\n```{r routes, echo=FALSE, eval=FALSE}\nlwd \u003c- desire_lines$foot\nroutes \u003c- routes_fast_sf[2:6, ]\nplot(routes$geometry, lwd = lwd)\nplot(desire_lines$geometry, col = \"green\", lwd = lwd, add = TRUE)\n```\n\nFor more examples, `example(\"route\")`.\n\n`overline()` takes a series of route-allocated lines,\nsplits them into unique segments and aggregates\nthe values of overlapping lines. This can represent where there will be\nmost traffic on the transport system, as demonstrated in the following code chunk. \n\n```{r rnet, warning=FALSE}\nroutes$foot \u003c- desire_lines$foot\nrnet \u003c- overline(routes, attrib = \"foot\")\n```\n\nThe resulting route network, with segment totals calculated from overlapping parts for the routes for walking, can be visualised as follows:\n\n```{r}\nplot(rnet[\"foot\"], lwd = rnet$foot)\n```\n\nThe above plot represents the number walking trips made (the 'flow') along particular segments of a transport network.\n\n\u003c!-- (results not shown): --\u003e\n\n```{r, routes-leaf, eval=FALSE, echo=FALSE}\nlibrary(leaflet)\npal = leaflet::colorNumeric(palette = \"YlGnBu\", domain = rnet$all)\nleaflet(data = rnet) %\u003e%\n  addProviderTiles(providers$OpenStreetMap.BlackAndWhite) %\u003e%\n  addPolylines(weight = rnet$all / 3, color = ~pal(all), opacity = 0.9) %\u003e% \n  addLegend(pal = pal, values = ~all)\n```\n\n## Policy applications\n\nThe examples shown above, based on tiny demonstration datasets, may not seem particularly revolutionary.\nAt 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.\n\nResults 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).\n**stplanr** is helping dozens of local authorities across the UK to answer the question: where to prioritise investment in cycling?\nIn essence, stplanr was designed to support sustainable transport policies.\n\nThere are many other research and policy questions that functions in **stplanr**, and other open source software libraries and packages, can help answer.\nAt 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.\n\n## Installation\n\nTo install the stable version, use:\n\n```{r, eval=FALSE}\ninstall.packages(\"stplanr\")\n```\n\nThe development version can be installed using **devtools**:\n\n```{r, eval=FALSE}\n# install.packages(\"devtools\") # if not already installed\ndevtools::install_github(\"ropensci/stplanr\")\nlibrary(stplanr)\n```\n\n### Installing stplanr on Linux and Mac\n\n**stplanr** depends on **sf**. Installation instructions for Mac, Ubuntu and other Linux distros can be found here: https://github.com/r-spatial/sf#installing\n\n## Funtions, help and contributing\n\nThe 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:\n\n```{r, eval=FALSE}\nlsf.str(\"package:stplanr\", all = TRUE)\n```\n\nTo get internal help on a specific function, use the standard way.\n\n```{r, eval=FALSE}\n?od2line\n```\n\nTo contribute, report bugs or request features, see the [issue tracker](https://github.com/ropensci/stplanr/issues).\n\n```{r, eval=FALSE, echo=FALSE}\n# Aim: explore dependencies\ndesc = read.dcf(\"DESCRIPTION\")\nheadings = dimnames(desc)[[2]]\nfields = which(headings %in% c(\"Depends\", \"Imports\", \"Suggests\"))\npkgs = paste(desc[fields], collapse = \", \")\npkgs = gsub(\"\\n\", \" \", pkgs)\nstrsplit(pkgs, \",\")[[1]]\ninstall.packages(\"miniCRAN\")\nlibrary(miniCRAN)\ntags \u003c- \"stplanr\"\npkgDep(tags)\ndg \u003c- makeDepGraph(tags, enhances = TRUE)\nset.seed(1)\nplot(dg, legendPosition = c(-1, 1), vertex.size = 20)\nlibrary(DiagrammeR)\nDiagrammeR::visnetwork(dg)\nvisNetwork::visIgraph(dg)\n```\n\n## Further resources / tutorials\n\nWant to learn how to use open source software for reproducible sustainable transport planning work?\nNow is a great time to learn.\nTransport planning is a relatively new field of application in R.\nHowever, there are already some good resources on the topic, including (any further suggestions: welcome):\n\n- The Transport chapter of *Geocomputation with R*, which provides a broad introduction from a geographic data perspective: https://r.geocompx.org/transport.html\n- 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)\n- The `dodgr` vignette, which provides an introduction to routing in R: https://github.com/UrbanAnalyst/dodgr\n\n## Meta\n\n* Please report issues, feature requests and questions to the [github issue tracker](https://github.com/ropensci/stplanr/issues)\n* License: MIT\n* Get citation information for **stplanr** in R doing `citation(package = 'stplanr')`\n* This project is released with a [Contributor Code of Conduct](https://github.com/ropensci/stplanr/blob/master/CONDUCT.md).\nBy participating in this project you agree to abide by its terms.\n\n[![rofooter](https://ropensci.org/public_images/github_footer.png)](https://ropensci.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fstplanr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Fstplanr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Fstplanr/lists"}