Description Usage Arguments Value Details Examples
View source: R/set_trip_speed.R
Sets the average speed of each specified trip_id
by changing the
arrival_time
and departure_time
columns in stop_times
.
1 | set_trip_speed(gtfs, trip_id, speed, unit = "km/h", by_reference = FALSE)
|
gtfs |
A GTFS object as created by |
trip_id |
A string vector including the |
speed |
A numeric representing the speed to be set. Its length must
either equal 1, in which case the value is recycled for all
|
unit |
A string representing the unit in which the speed is given. One
of |
by_reference |
Whether to update |
If by_reference
is set to FALSE
, returns a GTFS object
with the time columns of its stop_times
adjusted. Else, returns a
GTFS object invisibly (note that in this case the original GTFS object is
altered).
The average speed is calculated as the difference between the arrival time at
the last stop minus the departure time at the first top, over the trip's
length (as calculated via get_trip_geometry
, based on the
shapes
file). The arrival and departure times at all other stops (i.e.
not the first neither the last) are set as ""
, which is written as
NA
with write_gtfs
. Some transport routing software,
such as OpenTripPlanner, support
specifying stop times like so. In such cases, they estimate arrival/departure
times at the others stops based on the average speed as well. We plan to add
that feature to this function in the future.
1 2 3 4 5 6 7 8 9 10 11 12 13 | data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
gtfs_new_speed <- set_trip_speed(gtfs, trip_id = "CPTM L07-0", 50)
gtfs_new_speed$stop_times[trip_id == "CPTM L07-0"]
# original gtfs remains unchanged
gtfs$stop_times[trip_id == "CPTM L07-0"]
# now do it by reference
set_trip_speed(gtfs, trip_id = "CPTM L07-0", 50, by_reference = TRUE)
gtfs$stop_times[trip_id == "CPTM L07-0"]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.