MyNixOS website logo
Description

Routing with 'GTFS' (General Transit Feed Specification) Data.

Use 'GTFS' (General Transit Feed Specification) data for routing from nominated start and end stations, for extracting 'isochrones', and travel times from any nominated start station to all other stations.

gtfsrouter

R buildstatus codecov Project Status:Active CRAN_Status_Badge CRANDownloads

R package for public transport routing with GTFS (General Transit Feed Specification) data.

Installation

You can install latest stable version of gtfsrouter from CRAN with:

install.packages ("gtfsrouter")

Alternatively, the current development version can be installed using any of the following options:

# install.packages("remotes")
remotes::install_git ("https://git.sr.ht/~mpadge/gtfsrouter")
remotes::install_git ("https://codeberg.org/UrbanAnalyst/gtfsrouter")
remotes::install_bitbucket ("urbananalyst/gtfsrouter")
remotes::install_gitlab ("UrbanAnalyst/gtfsrouter")
remotes::install_github ("UrbanAnalyst/gtfsrouter")

To load the package and check the version:

library (gtfsrouter)
packageVersion ("gtfsrouter")
## [1] '0.0.5.158'

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 the temporary directory (tempdir()) of the current R session with the function berlin_gtfs_to_zip().

filename <- berlin_gtfs_to_zip ()
print (filename)
## [1] "/tmp/RtmpeXCbTq/vbb.zip"

For normal package use, filename will specify the name of a local GTFS .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, day = "Wed") # A pre-processing step to speed up queries
gtfs_route (gtfs,
    from = "Tegel",
    to = "Berlin Hauptbahnhof",
    start_time = 12 * 3600 + 120
) # 12:02 in seconds
route_nametrip_namestop_namearrival_timedeparture_time
U8U Paracelsus-BadU Schonleinstr. (Berlin)12:04:0012:04:00
U8U Paracelsus-BadU Kottbusser Tor (Berlin)12:06:0012:06:00
U8U Paracelsus-BadU Moritzplatz (Berlin)12:08:0012:08:00
U8U Paracelsus-BadU Heinrich-Heine-Str. (Berlin)12:09:3012:09:30
U8U Paracelsus-BadS+U Jannowitzbrucke (Berlin)12:10:3012:10:30
S5S WestkreuzS+U Jannowitzbrucke (Berlin)12:15:2412:15:54
S5S WestkreuzS+U Alexanderplatz Bhf (Berlin)12:17:2412:18:12
S5S WestkreuzS Hackescher Markt (Berlin)12:19:2412:19:54
S5S WestkreuzS+U Friedrichstr. Bhf (Berlin)12:21:2412:22:12
S5S WestkreuzS+U Berlin Hauptbahnhof12:24:0612:24:42

gtfs_traveltimes

The gtfs_traveltimes() function` calculates minimal travel times from any nominated stop to all other stops within a feed. It requires the two parameters of start station, and a vector of two values specifying earliest and latest desired start times. The following code returns the fastest travel times to all stations within the feed for services which leave the nominated station (“Alexanderplatz”) between 12:00 and 13:00 on a Monday:

gtfs <- extract_gtfs (filename)
gtfs <- gtfs_timetable (gtfs, day = "Monday")
x <- gtfs_traveltimes (gtfs,
    from = "Alexanderplatz",
    start_time_limits = c (12, 13) * 3600
)

The function returns a simple table detailing all stations reachable with services departing from the nominated station and start times:

head (x)
start_timedurationntransfersstop_idstop_namestop_lonstop_lat
12:00:4200:14:421060003102223S Bellevue (Berlin)13.3471052.51995
12:00:4200:08:360060003102224S Bellevue (Berlin)13.3471052.51995
12:00:4200:15:061060003103233S Tiergarten (Berlin)13.3362452.51396
12:00:4200:10:420060003103234S Tiergarten (Berlin)13.3362452.51396
12:00:4200:14:181060003201213S+U Berlin Hauptbahnhof13.3689252.52585
12:00:4200:05:540060003201214S+U Berlin Hauptbahnhof13.3689252.52585

Further details are provided in a separate vignette.

gtfs_transfer_table

Feeds should include a “transfers.txt” table detailing all possible transfers between nearby stations, yet many feeds omit these tables, rendering them unusable for routing because transfers between services can not be calculated. 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 pedestrian times routed through the underlying street network.

This function can also be used to enable routing through multiple adjacent or overlapping GTFS feeds. The feeds need simply be merged through binding the rows of all tables, and the resultant aggregate feed submitted to the gtfs_transfer_table() function. This transfer table will retain all transfers specified in the original feeds, yet be augmented by all possible transfers between the multiple systems up to a user-specified maximal distance. Further details of this function are also provided in another separate vignette.

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 routing.

Contributors

All contributions to this project are gratefully acknowledged using the allcontributors package following the all-contributors specification. Contributions of any kind are welcome!

Code


mpadge

AlexandraKapp

stmarcin

dhersz

polettif

Issue Authors


sridharraman

orlandombaa

Maxime2506

chinhqho

federicotallis

rafapereirabr

dcooley

bernd886

stefan-overkamp

luukvdmeer

szaboildi

cseveren

jh0ker

zamirD123

viajerus

jmertic

5balls

pteridin

Issue Contributors


tbuckl

tuesd4y

Robinlovelace

loanho23

abyrd

hansmib.
Metadata

Version

0.1.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows