edit_speed: Adjust Travel Speed in a GTFS Dataset

View source: R/edit_speed.R

edit_speedR Documentation

Adjust Travel Speed in a GTFS Dataset

Description

The 'edit_speed' function adjusts the travel speeds between stops in a GTFS dataset by modifying trip durations based on a specified speed multiplier. It allows selective adjustments for specific trips and stops or applies changes globally across the dataset.

Usage

edit_speed(gtfs, trips = "all", stops = "all", factor)

Arguments

gtfs

A GTFS object, preferably of class 'wizardgtfs'. If not, the function attempts to convert it using 'GTFSwizard::as_wizardgtfs()'.

trips

A character vector specifying the 'trip_id's to modify. Defaults to '"all"' to include all trips.

stops

A character vector specifying the 'stop_id's to include in the adjustment. Defaults to '"all"' to include all stops.

factor

A numeric value representing the multiplier for the speed. For example, a value of '2' doubles the speed, halving the travel time.

Details

The function performs the following steps:

1. Retrieve Durations

The 'get_durations()' function calculates trip durations, filtered by the specified trips and stops.

2. Adjust Durations

Durations are divided by the speed factor to compute new durations. Time differences are calculated.

3. Update Stop Times

Cumulative time differences are added to the 'arrival_time' and 'departure_time' columns in the 'stop_times' table.

If no specific trips or stops are provided, the function adjusts all trips and stops in the GTFS object.

Value

A GTFS object with updated 'stop_times' reflecting the adjusted travel durations.

Note

Ensure that the 'factor' is greater than 0. Using a value less than or equal to 0 will result in invalid or nonsensical time adjustments.

See Also

[GTFSwizard::get_speeds()]

Examples

edit_speed(for_rail_gtfs,
          trips = for_rail_gtfs$trips$trip_id[1:2],
          stops = for_rail_gtfs$stops$stop_id[1:2],
          factor = 1.5)


GTFSwizard documentation built on April 4, 2025, 4:10 a.m.