Learn R Programming

tidytransit (version 1.7.0)

stop_distances: Calculate distances between a given set of stops

Description

Calculate distances between a given set of stops

Usage

stop_distances(gtfs_stops)

Value

Returns a data.frame with each row containing a pair of stop_ids (columns from_stop_id and to_stop_id) and the distance between them (in meters)

Arguments

gtfs_stops

gtfs stops table either as data frame (with at least stop_id, stop_lon and stop_lat columns) or as sf object.

Examples

Run this code
if (FALSE) {
library(dplyr)

nyc_path <- system.file("extdata", "nyc_subway.zip", package = "tidytransit")
nyc <- read_gtfs(nyc_path)

nyc$stops %>%
  filter(stop_name == "Borough Hall") %>%
  stop_distances() %>%
  arrange(desc(distance))

#> # A tibble: 36 × 3
#>    from_stop_id to_stop_id  distance
#>                      
#>  1 423          232             91.5
#>  2 423N         232             91.5
#>  3 423S         232             91.5
#>  4 423          232N            91.5
#>  5 423N         232N            91.5
#>  6 423S         232N            91.5
#>  7 423          232S            91.5
#>  8 423N         232S            91.5
#>  9 423S         232S            91.5
#> 10 232          423             91.5
#> # … with 26 more rows
}

Run the code above in your browser using DataLab