GTFS Router
R package for routing with GTFS (General Transit Feed Specification) data. See the website for full details.
Installation
To install:
remotes::install_github("atfutures/gtfs-router")You can install latest stable version of gtfsrouter from CRAN with:
install.packages("gtfsrouter") # current CRAN versionAlternatively, current development versions can be installed using any of the following options:
# install.packages("remotes")
remotes::install_git("https://git.sr.ht/~mpadge/gtfsrouter")
remotes::install_bitbucket("atfutures/gtfsrouter")
remotes::install_gitlab("atfutures1/gtfsrouter")
remotes::install_github("ATFutures/gtfsrouter")To load the package and check the version:
library(gtfsrouter)
packageVersion("gtfsrouter")## [1] '0.0.1.31'
Main functions
The main functions can be demonstrated with sample data included with
the package from Berlin (the Verkehrverbund Berlin Brandenburg, or VBB).
GTFS data are always stored as .zip files, and these sample data can
be written to local storage with the function berlin_gtfs_to_zip().
berlin_gtfs_to_zip()
tempfiles <- list.files (tempdir (), full.names = TRUE)
filename <- tempfiles [grep ("vbb.zip", tempfiles)]
filename## [1] "/tmp/RtmpctrGeB/vbb.zip"
For normal package use, filename will specify the name of the local
GTFS data stored as a single .zip file.
gtfs_route
Given the name of a GTFS .zip file, filename, routing is as simple
as the following code:
gtfs <- extract_gtfs (filename)
gtfs <- gtfs_timetable (gtfs) # A pre-processing step to speed up queries
gtfs_route (gtfs,
from = "Schonlein",
to = "Berlin Hauptbahnhof",
start_time = 12 * 3600 + 120) # 12:02 in seconds| route_name | trip_name | stop_name | arrival_time | departure_time |
|---|---|---|---|---|
| U8 | U Paracelsus-Bad | U Schonleinstr. (Berlin) | 12:04:00 | 12:04:00 |
| U8 | U Paracelsus-Bad | U Kottbusser Tor (Berlin) | 12:06:00 | 12:06:00 |
| U8 | U Paracelsus-Bad | U Moritzplatz (Berlin) | 12:08:00 | 12:08:00 |
| U8 | U Paracelsus-Bad | U Heinrich-Heine-Str. (Berlin) | 12:09:30 | 12:09:30 |
| U8 | U Paracelsus-Bad | S+U Jannowitzbrucke (Berlin) | 12:10:30 | 12:10:30 |
| S5 | S Westkreuz | S+U Jannowitzbrucke (Berlin) | 12:15:24 | 12:15:54 |
| S5 | S Westkreuz | S+U Alexanderplatz Bhf (Berlin) | 12:17:24 | 12:18:12 |
| S5 | S Westkreuz | S Hackescher Markt (Berlin) | 12:19:24 | 12:19:54 |
| S5 | S Westkreuz | S+U Friedrichstr. Bhf (Berlin) | 12:21:24 | 12:22:12 |
| S5 | S Westkreuz | S+U Berlin Hauptbahnhof | 12:24:06 | 12:24:42 |
gtfs_isochrone
Isochrones from a nominated station - lines delineating the range
reachable within a given time - can be extracted with the
gtfs_isochrone() function, which returns a list of all stations
reachable within the specified time period from the nominated station.
gtfs <- extract_gtfs (filename)
gtfs <- gtfs_timetable (gtfs) # A pre-processing step to speed up queries
x <- gtfs_isochrone (gtfs,
from = "Schonlein",
start_time = 12 * 3600 + 120,
end_time = 12 * 3600 + 720) # 10 minutes laterThe function returns an object of class gtfs_isochrone containing
sf-formatted sets of start and end
points, along with all intermediate (“mid”) points, and routes. An
additional item contains the non-convex (alpha) hull enclosing the
routed points. This requires the packages
geodist,
sf,
alphahull, and
mapview to be installed.
Isochrone objects have their own plot method:
plot (x)The isochrone hull also quantifies its total area and width-to-length ratio.
Additional Functionality
There are many ways to construct GTFS feeds. For background information,
see gtfs.org, and particularly their GTFS
Examples.
Feeds may include a “frequencies.txt” table which defines “service
periods”, and overrides any schedule information during the specified
times. The gtfsrouter package includes a function,
frequencies_to_stop_times(),
to convert “frequencies.txt” tables to equivalent “stop_times.txt”
entries, to enable the feed to be used for routine.
Feeds may also omit a “transfers.txt” table which otherwise defines
transfer abilities and times between different services. Feeds without
this table can generally not be used for routing, and they exclude the
possibility of transferring between multiple services. The gtfsrouter
package also includes a function,
gtfs_transfer_table(),
which can calculate a transfer table for a given feed, with transfer
times calculated either using straight-line distances (the default), or
using more realistic times routed through the underlying street network.
Contributors
This project uses the allcontributor
package following the
all-contributors specification.
Contributions of any kind are welcome!
Code
|
mpadge |
AlexandraKapp |
stmarcin |
Issue Authors
|
polettif |
tbuckl |
sridharraman |
tuesd4y |
luukvdmeer |
Robinlovelace |
orlandoandradeb |
|
Maxime2506 |
chinhqho |
federicotallis |
rafapereirabr |
loanho23 |
