View source: R/set_route_speed.R
| set_route_speed | R Documentation |
Sets the average speed of the trips of each specified route_id, or of a
segment of them, by changing the arrival_time and departure_time columns
in stop_times.
set_route_speed(
gtfs,
route_id = NULL,
speed,
unit = "km/h",
first_stop = NULL,
last_stop = NULL,
from = NULL,
to = NULL,
route_type = NULL,
by_reference = FALSE
)
gtfs |
A GTFS object, as created by |
route_id |
A character vector including the |
speed |
A number representing the speed to be set for the trips of all
|
unit |
A string representing the unit in which the speed is given. One
of |
first_stop |
A string. The |
last_stop |
A string. The |
from |
A string, in the "HH:MM:SS" format. Only trips that depart from
the segment's first stop at or after |
to |
A string, in the "HH:MM:SS" format. Only trips that depart from
the segment's first stop at or before |
route_type |
An integer vector 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).
Every trip of each route, as listed in trips, gets the given speed, as
in set_trip_speed(), whose details also apply here: the duration of each
trip's segment (by default, the whole trip) is set to its length divided by
speed, the times at stops inside the segment are set to "", and from
and to restrict the changes to the trips that depart from the segment's
first stop within the time of day. Warnings about trips that can't be
changed refer to their trip_ids. Trips without stop_times entries are
ignored.
set_trip_speed(), get_trip_speed(), get_route_speed()
library(dplyr)
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
get_route_speed(gtfs, route_id = "CPTM L07")
new_speed_gtfs <- set_route_speed(gtfs, route_id = "CPTM L07", speed = 50)
get_route_speed(new_speed_gtfs, route_id = "CPTM L07")
# set the speed only of the trips that depart within a time of day
poa_path <- system.file("extdata/poa_gtfs.zip", package = "gtfstools")
poa_gtfs <- read_gtfs(poa_path)
poa_new_speed <- set_route_speed(
poa_gtfs,
route_id = "T2",
speed = 25,
from = "07:00:00",
to = "09:00:00"
)
# the arrival at the last stop of a trip that departs at 07:02 changes
poa_gtfs$stop_times |>
filter(trip_id == "T2-1@1#702") |>
slice_tail(n = 1)
poa_new_speed$stop_times |>
filter(trip_id == "T2-1@1#702") |>
slice_tail(n = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.