Sets the average speed of each specified
trip_id by changing the
departure_time columns in
set_trip_speed(gtfs, trip_id, speed, unit = "km/h", by_reference = FALSE)
A GTFS object, as created by
A string vector including the
A numeric representing the speed to be set. Its length must
either equal 1, in which case the value is recycled for all
A string representing the unit in which the speed is given. One
Whether to update
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
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
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.
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"] # use the unit argument to change the speed unit gtfs_new_speed <- set_trip_speed( gtfs, trip_id = "CPTM L07-0", speed = 15, unit = "m/s" ) gtfs_new_speed$stop_times[trip_id == "CPTM L07-0"] # original gtfs remains unchanged gtfs$stop_times[trip_id == "CPTM L07-0"] # when doing by reference, original gtfs is changed 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.