Learn R Programming

Description

gtsf is an R package for using GTFS data as simple features. You can also use it to make shapefiles and geojson from GTFS data.

Installation

You can install this package from GitHub using the devtools package:

if (!require(devtools)) {
    install.packages('devtools')
}
devtools::install_github('r-gtfs/gtsf')

Example Usage

Import transit lines from the NYC Subway using trread.

library(trread)
library(gtsf)
library(dplyr)

NYC <- import_gtfs("http://web.mta.info/developers/data/nyct/subway/google_transit.zip")
#> [1] "agency.txt"         "calendar_dates.txt" "calendar.txt"      
#> [4] "routes.txt"         "shapes.txt"         "stop_times.txt"    
#> [7] "stops.txt"          "transfers.txt"      "trips.txt"

Get Simple Features

NYC <- gtfs_as_sf(NYC)

This adds two simple features dataframes to the list of GTFS objects: -stops_sf -routes_sf

Make Maps

These can be mapped with various libraries. For example, with the tmap package:

library(tmap)
routes_sf <- NYC$sf_routes
qtm(routes_sf)

Export (GeoJSON/Shapefile)

They can also be exported to geojson, for use elsewhere. For example:

library(sf)
st_write(NYC$sf_routes,"nyc_routes.geojson", delete_dsn = TRUE)
#> Deleting source `nyc_routes.geojson' failed
#> Writing layer `nyc_routes' to data source `nyc_routes.geojson' using driver `GeoJSON'
#> features:       25
#> fields:         1
#> geometry type:  Multi Line String

Copy Link

Version

Install

install.packages('gtsf')

Monthly Downloads

2

Version

0.1.0

License

GPL

Issues

Pull Requests

Stars

Forks

Maintainer

Tom Buckley

Last Published

July 5th, 2018

Functions in gtsf (0.1.0)

routes_df_as_sf

Get a sf dataframe for gtfs routes
shapes_df_as_sfg

return an sf multilinestring with lat and long from gtfs for a route
gtfs_as_sf

Get common simple features (sf) for a gtfsr object
planner_buffer

Buffer using common urban planner distances
gtfs_obj

Example GTFS data
stops_for_route

Get a set of stops for a route
shapes_for_routes

Get a set of shapes for a set of routes
shape_route_service

Join the shapes, trips and routes tables together - also checks on some potential errors in the data and warns accordingly
shape_for_route

Get a set of shapes for a route
stops_df_as_sf

Get a sf dataframe for gtfs stops
stops_for_routes

Get a set of stops for a set of routes