View source: R/get_stop_distances.R
| get_stop_distances | R Documentation |
Returns the great-circle distance between each pair of stops visited by the given trips and/or routes.
get_stop_distances(gtfs, trip_id = NULL, route_id = NULL)
gtfs |
A GTFS object, as created by |
trip_id |
A character vector including the |
route_id |
A character vector including the |
A data.table with the columns from_stop_id, to_stop_id and
distance (in meters), with one row for each pair of distinct stops,
sorted by from_stop_id and to_stop_id. It is empty if fewer than two
stops are selected.
The stops are selected as in get_stops(): only the stops listed in the
stop_times entries of the selected trips are considered.
Distances are great-circle distances ("as the crow flies") between the stops' coordinates, not distances along the trips' shapes or the street network.
Each pair of stops appears only once, with the stop_id that comes first
in the C locale (the order used by data.table) as from_stop_id. If a
stop_id is listed more than once in stops, only its first entry is
used. Stops without coordinates have NA distances.
The size of the result grows with the square of the number of stops: about 1 GB of memory is used for 5,500 stops, and about 3 GB for 10,000 stops. A warning is raised when more than 1 GB is needed, so on large feeds please select only the trips or routes of interest. More than 65,536 stops can't be used at once, raising an error.
get_stops(), get_trip_length()
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
# distances between the stops visited by a trip
distances <- get_stop_distances(gtfs, trip_id = "CPTM L07-0")
head(distances)
# distances between the stops visited by the trips of a route
distances <- get_stop_distances(gtfs, route_id = "CPTM L07")
head(distances)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.