This repo presents a function convert a GTFS feed (or a list of GTFS feeds) into an igraph
object for network analysis in R
.
The workflow of the function is as follows:
- Step 0: Read the GTFS data into memory
- Steps 1 to 3: Identify and merge stops that are closer than a distance threshold (meters). This threshold is set by the user
- Step 4: Identify transport modes, route and service level for each trip
- Step 5: Indentify links between stops
- Step 6: Build igraph (L-space representation). As it stands, the script returns a graph with information on route frequecy and on travel time for each link that can be used to calculate weighted metrics
- Step 7 (optional): the script creates a subdirectory and saves the input files to use in MuxViz
This function needs three inputs:
- list with one or more files
gtfs.zip
- a distance threshold set in meters
- a logic value indicating whether you want to save input files to use latter in MuxViz
obs. This function was tested using the GTFS of Las Vegas, USA, downloaded on Oct. 2017. This file is made available in the GitHub repo but it can also be downloaded by running this line in R
:
download.file(url="http://rtcws.rtcsnv.com/g/google_transit.zip", destfile = "google_transit.zip")
# set working Directory
setwd("R:/Dropbox/github/gtfs_to_igraph")
# get a list of GTFS.zip files
my_gtfs_feeds <- list.files(path = ".", pattern =".zip", full.names = T)
# load function
source("gtfs_to_igraph.R")
# run function
g <- gtfs_to_igraph(list_gtfs = my_gtfs_feeds, dist_threshold =30 , save_muxviz =T)
- Allow the option whether graph is weighted by route frequency or by travel time
- Allow the option to build a multilayer network where each (route? or each transport mode?) is a different layer
- Mateo Neira has similar project in
Pyhton
, here. - Sandro Souza has written a Python script to study some properties and robustness of the public transport network of São Paulo. This was for his Masters dissertation, which it's available in Portuguese here
- Tyler Green has a similar project in
Java
to study transit system design using graph theory. - Last but not least, Manlio De Domenico has created MuxViz, which is well advanced platform for the visualization and the analysis of interconnected multilayer networks in
R
.