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")

To load the package and check the version:

library(gtfsrouter)
packageVersion("gtfsrouter")

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().

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:

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.

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

GTFS Structure

For background information, see gtfs.org, and particularly their GTFS Examples. The VBB is strictly schedule-only, so has no "frequencies.txt" file (this file defines “service periods”, and overrides any schedule information during the specified times).