View source: R/set_dwell_time.R
| set_dwell_time | R Documentation |
Sets the dwell time of each specified trip_id at each specified stop_id,
i.e. the time the vehicle stays at the stop, by changing the
departure_time at these stops in stop_times and shifting the later times
of the trips accordingly.
set_dwell_time(
gtfs,
dwell_time,
unit = "s",
trip_id = NULL,
stop_id = NULL,
from = NULL,
to = NULL,
route_type = NULL,
by_reference = FALSE
)
gtfs |
A GTFS object, as created by |
dwell_time |
A non-negative number, the dwell time to be set, in
|
unit |
A string representing the time unit in which |
trip_id |
A character vector including the |
stop_id |
A character vector including the |
from |
A string, in the "HH:MM:SS" format. Only visits whose arrival
time is at or after |
to |
A string, in the "HH:MM:SS" format. Only visits whose arrival time
is 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).
The dwell time of a visit is its departure_time minus its arrival_time
in stop_times, as returned by get_dwell_time(). It is set at the visits
of every specified trip to every specified stop (not of pairs formed by
their elements): the arrival time is kept and the departure time is set to
the arrival time plus dwell_time. All the later times of the trip, in
stop_sequence order, are shifted by the change, and changes at several
visits of the same trip add up. At a trip's last stop, only the departure
time changes. A stop visited more than once by the same trip has its dwell
time set at each visit.
Blank times are never filled. Selected visits with a blank arrival or
departure time are not changed and don't shift the later times, with a
warning when stop_id is given; fill them beforehand with
interpolate_stop_times(). An error is raised if a shift would result in a
negative time (times not in chronological order) or in a time later than
"9999:59:59". stop_sequence is assumed to be unique within each trip
and not NA. When both trip_id and stop_id are given but none of the
trips visits any of the stops, a warning is raised and the GTFS is returned
unchanged.
For trips listed in frequencies, the times in stop_times are a template
(see frequencies_to_stop_times()), so setting the dwell time at the first
stop only changes how long before each departure the vehicle arrives there,
while changes at later stops lengthen or shorten every departure.
from and to are compared with the arrival_time of each visit as
written in stop_times before any change (template times, for trips listed
in frequencies), so use times past "24:00:00" for arrivals after
midnight. A shift caused by an earlier visit may thus move a changed visit
out of the time of day, or another visit into it. Visits with a blank
arrival time are never selected when from or to is given. When the time
of day contains no visit of the specified trips to the specified stops, the
GTFS is returned unchanged.
stop_ids are matched against the stop_ids in stop_times, which are
never stations: to set the dwell times at a station, pass its children that
appear in stop_times (see get_children_stops()). Existing _secs
columns in stop_times (e.g. created with convert_time_to_seconds()) are
updated to match.
get_dwell_time(), set_min_dwell_time(), set_trip_speed()
library(dplyr)
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
# set a 30 seconds dwell time at a stop of a trip. the later times of the
# trip are shifted by 30 seconds
new_gtfs <- set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
stop_id = "18920",
dwell_time = 30
)
new_gtfs$stop_times |>
filter(trip_id == "CPTM L07-0") |>
head()
# set the dwell time at a stop in every trip that visits it. use the unit
# argument to give the dwell time in another unit
new_gtfs <- set_dwell_time(
gtfs,
stop_id = "18960",
dwell_time = 1,
unit = "min"
)
get_dwell_time(new_gtfs, stop_id = "18960")
# set the dwell time only at the visits that arrive within a time of day
new_gtfs <- set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
dwell_time = 30,
from = "05:00:00",
to = "06:00:00"
)
get_dwell_time(new_gtfs, trip_id = "CPTM L07-0")
# original gtfs remains unchanged
get_dwell_time(gtfs, stop_id = "18960")
# when doing by reference, original gtfs is changed
set_dwell_time(
gtfs,
trip_id = "CPTM L07-0",
stop_id = "18920",
dwell_time = 30,
by_reference = TRUE
)
gtfs$stop_times |>
filter(trip_id == "CPTM L07-0") |>
head()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.