Routing engine for GTFS (General Transit Feed Specification) data
Branch: master
Clone or download
Latest commit 057aec2 Feb 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R add test-isochrone Feb 17, 2019
data-raw add day param to timetable Feb 14, 2019
data add day param to timetable Feb 14, 2019
man update berlin_gtfs descr Feb 16, 2019
src 🎈tests Feb 19, 2019
tests add test-isochrone Feb 17, 2019
.Rbuildignore initial commit Jan 28, 2019
.gitignore initial commit Jan 28, 2019
.travis.yml 🎈tests Feb 19, 2019
DESCRIPTION add gtfs_isochrone fn; closes #3 Feb 15, 2019
NAMESPACE add gtfs_isochrone fn; closes #3 Feb 15, 2019
README.Rmd 🚀👓 Feb 16, 2019
README.md 🚀👓 Feb 16, 2019
appveyor.yml initial commit Jan 28, 2019
makefile

README.md

Build Status AppVeyor Build Status codecov Project Status: WIP

GTFS Router

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

Installation

To install:

remotes::install_github("atfutures/gtfs-router")

To load the package and check the version:

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

Main functions

The main functions can be demonstrated with sample data from Berlin (the Verkehrverbund Berlin Brandenburg, or VBB), included with the package. 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/Rtmp7UDP4d/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 stop departure_time arrival_time
U8 U Schonleinstr. (Berlin) 12:04:00 12:04:00
U8 U Kottbusser Tor (Berlin) 12:06:00 12:06:00
U8 U Moritzplatz (Berlin) 12:08:00 12:08:00
U8 U Heinrich-Heine-Str. (Berlin) 12:09:30 12:09:30
U8 S+U Jannowitzbrucke (Berlin) 12:10:30 12:10:30
S5 S+U Jannowitzbrucke (Berlin) 12:15:54 12:15:24
S5 S+U Alexanderplatz Bhf (Berlin) 12:18:12 12:17:24
S5 S Hackescher Markt (Berlin) 12:19:54 12:19:24
S5 S+U Friedrichstr. Bhf (Berlin) 12:22:12 12:21:24
S5 S+U Berlin Hauptbahnhof 12:24:42 12:24:06

A routing query on a very large network (the GTFS data are MB) takes only around 0.05 seconds.

gtfs_isochrone

Isochrones from a nominated station can be extracted with the gtfs_isochrone() function, returning a list of all stations reachable within a specified time period from that 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 later
head(x)
stop_name stop_lon stop_lat in_isochrone
1 U Rathaus Neukolln (Berlin) 13.43481 52.48115 TRUE
2 U Kottbusser Tor (Berlin) 13.41775 52.49905 TRUE
3 U Gorlitzer Bahnhof (Berlin) 13.42847 52.49903 TRUE
5 U Lipschitzallee (Berlin) 13.46311 52.42464 TRUE
6 U Franz-Neumann-Platz (Berlin) 13.36428 52.56385 TRUE
7 U Leinestr. (Berlin) 13.42840 52.47287 TRUE

The function returns a data.frame of all stations, with in_isochrone = TRUE for those reachable from the nominated station within the nominated time. The results of gtfs_isochrone can also be plotted as an interactive web map, simply by plot(x). This requires the packages sf, alphahull, and mapview to be installed.

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