View source: R/get_distances.R
get_distances | R Documentation |
The 'get_distances' function calculates distances within a 'wizardgtfs' object based on various methods. Depending on the 'method' chosen, it can calculate average route distances, trip-specific distances, or detailed distances between stops.
get_distances(gtfs, method = "by.route", trips = "all")
gtfs |
A GTFS object, ideally of class 'wizardgtfs'. If it is not of this class, it will be converted. |
method |
A character string indicating the calculation method. Choices are:
|
trips |
A character vector of trip IDs to consider. When set to 'all', includes all trips. |
The function calls specific sub-functions based on the selected method:
- "by.route": Calculates average distances per route.
- "by.trip": Calculate distances per trip.
- "detailed": Calculates detailed stop-to-stop distances within each route. Note that this method may be slow for large datasets.
If an invalid 'method' is provided, the function defaults to '"by.route"' and issues a warning.
A data frame with calculated distances based on the specified method:
Returns a summary with columns: 'route_id', 'trips', 'average.distance', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'route_id', 'trip_id', 'distance', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'shape_id', 'from_stop_id', 'to_stop_id', and 'distance'.
[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_servicepattern()]
# Calculate average route distances
distances_by_route <- get_distances(gtfs = for_rail_gtfs, method = "by.route", trips = 'all')
# Calculate distances by trip
distances_by_trip <- get_distances(gtfs = for_rail_gtfs, method = "by.trip", trips = 'all')
# Calculate detailed distances between stops
detailed_distances <- get_distances(gtfs = for_rail_gtfs, method = "detailed", trips = 'all')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.