Identifies spatial and spatiotemporal patterns within the stop_times
table. Please see the details to understand what a "pattern" means in each of
these cases.
Arguments
- gtfs
A GTFS object, as created by
read_gtfs().- trip_id
A character vector including the
trip_ids to have theirstop_timesentries analyzed. IfNULL(the default), the function analyses the pattern of everytrip_idin the GTFS.- type
A string specifying the type of patterns to be analyzed. Either
"spatial"(the default) or "spatiotemporal".- sort_sequence
Deprecated; do not supply. Timetables are now always sorted by
stop_sequence. PassingTRUEraises a warning, and passingFALSEraises an error.
Details
Two trips are assigned to the same spatial pattern_id if they travel along
the same sequence of stops. They are assigned to the same spatiotemporal
pattern_id, on the other hand, if they travel along the same sequence of
stops and they take the same time between stops. Please note that, in such
case, only the time between stops is taken into account, and the time that
the trip started is ignored (e.g. if two trips depart from stop A and follow
the same sequence of stops to arrive at stop B, taking both 1 hour to do so,
their spatiotemporal pattern will be considered the same, even if one
departed at 6 am and another at 7 am). Please also note that only the order
given by stop_sequence matters, not its values - e.g. if trip X lists stops
A followed by stop B with stop_sequences 1 and 2, and trip Y lists stops A
followed by stop B with stop_sequences 1 and 3, they are assigned to the
same pattern_id.
Existing _secs columns in stop_times (e.g. created with
convert_time_to_seconds()) are used as-is, not recalculated from the time
strings.
Examples
data_path <- system.file("extdata/ber_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
patterns <- get_stop_times_patterns(gtfs)
head(patterns)
#> Key: <trip_id>
#> trip_id pattern_id
#> <char> <int>
#> 1: 143765655 1
#> 2: 143765656 2
#> 3: 143765658 3
#> 4: 143765659 3
#> 5: 143765660 3
#> 6: 143765661 3
# use the trip_id argument to control which trips are analyzed
patterns <- get_stop_times_patterns(
gtfs,
trip_id = c("143765658", "143765659", "143765660")
)
patterns
#> Key: <trip_id>
#> trip_id pattern_id
#> <char> <int>
#> 1: 143765658 1
#> 2: 143765659 1
#> 3: 143765660 1
# use the type argument to control the type of pattern analyzed
patterns <- get_stop_times_patterns(
gtfs,
trip_id = c("143765658", "143765659", "143765660"),
type = "spatiotemporal"
)
patterns
#> Key: <trip_id>
#> trip_id pattern_id
#> <char> <int>
#> 1: 143765658 1
#> 2: 143765659 2
#> 3: 143765660 2
