knitr::opts_chunk$set(
  collapse = TRUE,
  cache = FALSE,
  comment = "#>",
  message = FALSE,
  error = FALSE,
  warning = FALSE,
  fig.path = "README/README-",
  fig.width=7.3,
  fig.height=5,
  out.width = '100%'
)

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

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)


r-gtfs/gtsf documentation built on May 8, 2019, 1:49 p.m.