| Title: | Creating, Exploring and Manipulating 'GTFS' Files |
|---|---|
| Description: | Creating, exploring, analyzing, and manipulating General Transit Feed Specification (GTFS) files, which represent public transportation schedules and geographic data. The package allows users to filter data by routes, trips, stops, service dates, and time, generate spatial visualizations, and perform detailed analyses of transit networks, including headway, dwell times, route frequencies, service span, scheduled vehicle-hours, and trip duration. Methods follow common public transport planning and operation concepts described in Ceder (2007, ISBN:978-0-7506-6166-6), Vuchic (2005, ISBN:978-0-471-63265-8), and Vuchic (2007, ISBN:978-0-471-75823-5). |
| Authors: | Nelson de Oliveira Quesado Filho [aut, cre], Caio Gustavo Coelho Guimarães [aut], Francisco Moraes de Oliveira Neto [aut] |
| Maintainer: | Nelson de Oliveira Quesado Filho <[email protected]> |
| License: | GPL-3 |
| Version: | 1.2.0 |
| Built: | 2026-06-22 19:31:22 UTC |
| Source: | https://github.com/cran/GTFSwizard |
Converts a list-like GTFS feed to the class used by GTFSwizard. Character GTFS dates are converted to [Date] values, a date-to-service lookup is created, and missing shapes can optionally be inferred from stop locations.
as_wizardgtfs(gtfs_list, build_shapes = TRUE)as_wizardgtfs(gtfs_list, build_shapes = TRUE)
gtfs_list |
A named list of GTFS tables or a 'tidygtfs' object. |
build_shapes |
Logical. If 'TRUE', infer 'shapes' when the table is absent. Inferred shapes connect stops with straight line segments and are intended for analysis and visualization, not map-matched routing. |
The input is checked for required tables, required fields, primary-key duplication, foreign-key consistency, increasing stop and shape sequences, valid service dates, and valid GTFS time strings. Times remain character values because GTFS permits hours greater than 24.
A 'wizardgtfs' object.
[GTFSwizard::create_gtfs()], [GTFSwizard::get_shapes()]
gtfs_wizard <- as_wizardgtfs(for_rail_gtfs, build_shapes = TRUE)gtfs_wizard <- as_wizardgtfs(for_rail_gtfs, build_shapes = TRUE)
Creates and validates a GTFS Schedule feed from data frames. The required files and fields follow the current GTFS Schedule reference, including its conditional rules for route names, stop locations, and service calendars.
create_gtfs( agency, routes, trips, stop_times, stops, calendar = NULL, calendar_dates = NULL, shapes = NULL, frequencies = NULL, transfers = NULL, fare_attributes = NULL, fare_rules = NULL, build_shapes = TRUE, zipfile = NULL, ... )create_gtfs( agency, routes, trips, stop_times, stops, calendar = NULL, calendar_dates = NULL, shapes = NULL, frequencies = NULL, transfers = NULL, fare_attributes = NULL, fare_rules = NULL, build_shapes = TRUE, zipfile = NULL, ... )
agency, routes, trips, stop_times, stops
|
Required GTFS tables supplied as data frames. 'agency_id' may be omitted when the feed contains one agency. |
calendar, calendar_dates
|
Service calendar tables. At least one must define every 'service_id' used by 'trips'. |
shapes, frequencies, transfers, fare_attributes, fare_rules
|
Optional GTFS tables. |
build_shapes |
Logical. If 'TRUE', infer straight-line shapes when 'shapes' is not supplied. |
zipfile |
Optional output path ending in '.zip'. |
... |
Additional named GTFS tables, such as 'pathways', 'levels', 'feed_info', or GTFS Fares v2 tables. |
A validated 'wizardgtfs' object, invisibly written as well when 'zipfile' is supplied.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/)
feed <- create_gtfs( agency = data.frame( agency_id = "A", agency_name = "Demo Transit", agency_url = "https://example.com", agency_timezone = "America/Fortaleza" ), routes = data.frame( route_id = "R1", agency_id = "A", route_short_name = "1", route_long_name = "Central", route_type = 3 ), trips = data.frame(route_id = "R1", service_id = "WK", trip_id = "T1"), stop_times = data.frame( trip_id = "T1", arrival_time = c("08:00:00", "08:10:00"), departure_time = c("08:00:00", "08:10:00"), stop_id = c("S1", "S2"), stop_sequence = c(1, 2) ), stops = data.frame( stop_id = c("S1", "S2"), stop_name = c("First", "Second"), stop_lat = c(-3.73, -3.74), stop_lon = c(-38.52, -38.53) ), calendar = data.frame( service_id = "WK", monday = 1, tuesday = 1, wednesday = 1, thursday = 1, friday = 1, saturday = 0, sunday = 0, start_date = "20260101", end_date = "20261231" ) )feed <- create_gtfs( agency = data.frame( agency_id = "A", agency_name = "Demo Transit", agency_url = "https://example.com", agency_timezone = "America/Fortaleza" ), routes = data.frame( route_id = "R1", agency_id = "A", route_short_name = "1", route_long_name = "Central", route_type = 3 ), trips = data.frame(route_id = "R1", service_id = "WK", trip_id = "T1"), stop_times = data.frame( trip_id = "T1", arrival_time = c("08:00:00", "08:10:00"), departure_time = c("08:00:00", "08:10:00"), stop_id = c("S1", "S2"), stop_sequence = c(1, 2) ), stops = data.frame( stop_id = c("S1", "S2"), stop_name = c("First", "Second"), stop_lat = c(-3.73, -3.74), stop_lon = c(-38.52, -38.53) ), calendar = data.frame( service_id = "WK", monday = 1, tuesday = 1, wednesday = 1, thursday = 1, friday = 1, saturday = 0, sunday = 0, start_date = "20260101", end_date = "20261231" ) )
Adds a number of seconds to every non-empty arrival and departure time for selected trips. GTFS times above 24 hours are preserved.
delay_trip(gtfs, trip, duration)delay_trip(gtfs, trip, duration)
gtfs |
A GTFS object. |
trip |
Character vector of 'trip_id' values. |
duration |
Numeric seconds or an object coercible to seconds, such as a 'difftime'. |
A modified 'wizardgtfs' object.
[GTFSwizard::edit_speed()], [GTFSwizard::set_dwelltime()]
delayed <- delay_trip( for_rail_gtfs, trip = for_rail_gtfs$trips$trip_id[1:2], duration = 300 )delayed <- delay_trip( for_rail_gtfs, trip = for_rail_gtfs$trips$trip_id[1:2], duration = 300 )
Multiplies dwell time at selected trip-stop calls and propagates each change to all later times in the same trip. Arrival at the edited stop is retained; departure and subsequent calls move by the dwell-time difference.
edit_dwelltime(gtfs, trips = "all", stops = "all", factor)edit_dwelltime(gtfs, trips = "all", stops = "all", factor)
gtfs |
A GTFS object. |
trips, stops
|
Character ID vectors or '"all"'. |
factor |
One non-negative numeric multiplier. |
A modified 'wizardgtfs' object.
[GTFSwizard::set_dwelltime()], [GTFSwizard::get_dwelltimes()]
edited <- edit_dwelltime( for_rail_gtfs, trips = for_rail_gtfs$trips$trip_id[1:2], stops = for_rail_gtfs$stops$stop_id[1:2], factor = 1.5 )edited <- edit_dwelltime( for_rail_gtfs, trips = for_rail_gtfs$trips$trip_id[1:2], stops = for_rail_gtfs$stops$stop_id[1:2], factor = 1.5 )
Changes travel time between consecutive stops by dividing it by a speed multiplier. Dwell times are preserved and all downstream times are shifted.
edit_speed(gtfs, trips = "all", stops = "all", factor)edit_speed(gtfs, trips = "all", stops = "all", factor)
gtfs |
A GTFS object. |
trips |
Character trip IDs or '"all"'. |
stops |
Character stop IDs or '"all"'. A segment is edited when either endpoint is selected. |
factor |
One positive speed multiplier. For example, '2' halves segment travel times. |
A modified 'wizardgtfs' object.
[GTFSwizard::get_speeds()], [GTFSwizard::get_durations()]
edited <- edit_speed( for_rail_gtfs, trips = for_rail_gtfs$trips$trip_id[1:2], stops = "all", factor = 1.25 )edited <- edit_speed( for_rail_gtfs, trips = for_rail_gtfs$trips$trip_id[1:2], stops = "all", factor = 1.25 )
Opens a lightweight Shiny dashboard for exploring a GTFS feed. The dashboard shows summary cards, route and stop maps, service calendar, and key operational charts. Route, service, service-pattern, stop, date, and time filters update the dashboard without changing the original object.
explore_gtfs(gtfs = NULL)explore_gtfs(gtfs = NULL)
gtfs |
A GTFS object, preferably of class 'wizardgtfs'. When omitted or 'NULL' in an interactive session, a file-selection window opens so the user can choose a GTFS '.zip' archive. |
A Shiny app object.
[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_shapes()], [GTFSwizard::plot_calendar()]
if (interactive()) { explore_gtfs() explore_gtfs(GTFSwizard::for_rail_gtfs) }if (interactive()) { explore_gtfs() explore_gtfs(GTFSwizard::for_rail_gtfs) }
Filters a GTFS feed while preserving referential integrity across routes, trips, stops, shapes, calendars, frequencies, fares, and transfers.
filter_servicepattern(gtfs, servicepattern = NULL) filter_date(gtfs, dates = NULL) filter_service(gtfs, service) filter_route(gtfs, route, keep = TRUE) filter_trip(gtfs, trip, keep = TRUE) filter_stop(gtfs, stop) filter_time(gtfs, from = "00:00:00", to = "48:00:00")filter_servicepattern(gtfs, servicepattern = NULL) filter_date(gtfs, dates = NULL) filter_service(gtfs, service) filter_route(gtfs, route, keep = TRUE) filter_trip(gtfs, trip, keep = TRUE) filter_stop(gtfs, stop) filter_time(gtfs, from = "00:00:00", to = "48:00:00")
gtfs |
A GTFS object. |
servicepattern |
Character vector of service-pattern IDs returned by [get_servicepattern()]. When 'NULL', the most frequent pattern is used. |
dates |
Dates to retain. Values accepted by [as.Date()] are supported. When 'NULL', the latest available service date is used. |
service, route, trip, stop
|
Character vectors of IDs to retain. |
keep |
Logical. If 'FALSE', the specified route or trip IDs are excluded. |
from, to
|
Inclusive GTFS time bounds in '"HH:MM:SS"' form. Hours may exceed 24. |
'filter_stop()' retains the requested stop calls and therefore may return partial trips. 'filter_time()' retains individual stop calls whose arrival or departure falls inside the inclusive time interval and may also return partial trips. This behavior is useful for network experiments. Route, trip, service, service-pattern, and date filters retain complete trips.
'filter_date()' rewrites service availability as 'calendar_dates' additions for exactly the selected dates. Other filters preserve the selected services' original date ranges and exceptions.
A 'wizardgtfs' object.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/)
[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_servicepattern()]
typical <- filter_servicepattern(for_rail_gtfs) one_day <- filter_date(for_rail_gtfs, "2021-02-10") one_route <- filter_route(for_rail_gtfs, for_rail_gtfs$routes$route_id[1]) two_trips <- filter_trip(for_rail_gtfs, for_rail_gtfs$trips$trip_id[1:2]) serving_stop <- filter_stop(for_rail_gtfs, for_rail_gtfs$stops$stop_id[1]) morning <- filter_time(for_rail_gtfs, from = "06:30:00", to = "10:00:00")typical <- filter_servicepattern(for_rail_gtfs) one_day <- filter_date(for_rail_gtfs, "2021-02-10") one_route <- filter_route(for_rail_gtfs, for_rail_gtfs$routes$route_id[1]) two_trips <- filter_trip(for_rail_gtfs, for_rail_gtfs$trips$trip_id[1:2]) serving_stop <- filter_stop(for_rail_gtfs, for_rail_gtfs$stops$stop_id[1]) morning <- filter_time(for_rail_gtfs, from = "06:30:00", to = "10:00:00")
A dataset containing GTFS (General Transit Feed Specification) data for Fortaleza's transit system by bus. The data includes information on routes, trips, stops, stop times, and other elements necessary for transit planning and analysis.
An object of class wizardgtfs, containing multiple data frames:
Data frame with 1 row and 7 columns, providing information about the transit agency, including agency name, URL, timezone, and contact details.
Data frame with 3 rows and 10 columns, detailing service availability by day of the week, start and end dates for each service.
Data frame with 2 rows and 6 columns, showing fare information, including price, currency, payment method, and transfer rules.
Data frame with 345 rows and 5 columns, linking fare IDs to routes, along with optional restrictions on origins, destinations, and zones.
Data frame with 345 rows and 9 columns, listing route details such as route ID, agency ID, route short and long names, route type, and colors.
Data frame with 125,776 rows and 5 columns, representing the spatial paths of routes with latitude, longitude, point sequence, and cumulative distance traveled.
Data frame with 2,659,737 rows and 9 columns, including stop times for each trip, with arrival and departure times, stop sequence, and stop ID information.
Data frame with 4,676 rows and 12 columns, containing information about each stop, including stop ID, name, location (latitude and longitude), and accessibility.
Data frame with 85,410 rows and 9 columns, detailing trips associated with routes, including trip IDs, route IDs, direction, block, and shape IDs.
The GTFS data format is widely used for representing public transportation schedules and associated geographic information. This dataset follows the GTFS standard and includes elements for advanced analysis in transit planning.
Fortaleza transit agency (ETUFOR).
# Load the dataset data(for_bus_gtfs) # Access trips data head(for_bus_gtfs$trips) # Access stops data head(for_bus_gtfs$stops)# Load the dataset data(for_bus_gtfs) # Access trips data head(for_bus_gtfs$trips) # Access stops data head(for_bus_gtfs$stops)
This dataset contains GTFS (General Transit Feed Specification) data for Fortaleza's rail transit system, managed by METROFOR. The data includes information on routes, trips, stops, stop times, shapes, and other necessary elements for transit analysis and planning.
An object of class wizardgtfs, consisting of multiple data frames:
Data frame with 1 row and 7 columns, providing information about the transit agency, including agency name, URL, timezone, language, and contact details.
Data frame with 1 row and 10 columns, detailing the service availability by day of the week, along with start and end dates for each service.
Data frame with 26 rows and 3 columns, listing specific dates and exceptions (e.g., holidays) that modify the usual service pattern.
Data frame with 3 rows and 9 columns, listing route details such as route ID, short and long names, route type, and colors associated with each route.
Data frame with 39 rows and 10 columns, containing information about each stop, including stop ID, name, location (latitude and longitude), and additional details.
Data frame with 3,420 rows and 10 columns, detailing arrival and departure times for each trip, along with stop sequences and stop IDs.
Data frame with 215 rows and 7 columns, providing trip-specific information such as trip ID, headsign, direction, associated service ID, route ID, and shape ID.
Data frame with 80 rows and 5 columns, representing spatial paths of routes using latitude, longitude, point sequence, and cumulative distance traveled.
The GTFS data format is widely adopted for representing public transportation schedules and spatial information. This dataset follows GTFS standards and is tailored for advanced analysis, particularly in transit planning and operations. Key tables included are 'agency', 'routes', 'stops', 'stop_times', 'trips', and 'shapes', each providing essential attributes for a comprehensive transit analysis.
Cia Cearense de Transportes Metropolitanos (METROFOR).
# Load the dataset data(for_rail_gtfs) # Access trips data head(for_rail_gtfs$trips) # Access stops data head(for_rail_gtfs$stops)# Load the dataset data(for_rail_gtfs) # Access trips data head(for_rail_gtfs$trips) # Access stops data head(for_rail_gtfs$stops)
Returns the departure at the lowest 'stop_sequence' for every trip.
get_1stdeparture(gtfs)get_1stdeparture(gtfs)
gtfs |
A GTFS object. |
A tibble with 'route_id', 'trip_id', 'departure_time', and 'stop_id'.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/#stop_timestxt)
head(get_1stdeparture(for_rail_gtfs))head(get_1stdeparture(for_rail_gtfs))
Finds frequently served adjacent stop pairs, joins connected pairs into corridors, and measures them in a local metric CRS.
get_corridor(gtfs, i = 0.01, min.length = 1500)get_corridor(gtfs, i = 0.01, min.length = 1500)
gtfs |
A GTFS object. |
i |
Proportion of the highest-frequency stop pairs to retain. Must be greater than 0 and no greater than 1. |
min.length |
Minimum corridor length in meters. |
An 'sf' object with 'corridor', list-columns 'stop_id' and 'trip_id', numeric 'length' in meters, and WGS84 geometry. Segments are straight lines between stop coordinates, not shape geometry.
[GTFSwizard::plot_corridor()]
corridors <- get_corridor(for_rail_gtfs, i = 0.2, min.length = 100)corridors <- get_corridor(for_rail_gtfs, i = 0.2, min.length = 100)
The 'get_distances' function calculates distances within a 'wizardgtfs' object based on various methods. Depending on the 'method' chosen, it can calculate average route distances, trip-specific distances, or detailed distances between stops.
get_distances(gtfs, method = "by.route", trips = "all")get_distances(gtfs, method = "by.route", trips = "all")
gtfs |
A GTFS object, ideally of class 'wizardgtfs'. If it is not of this class, it will be converted. |
method |
A character string indicating the calculation method. Choices are:
|
trips |
A character vector of trip IDs to consider. When set to 'all', includes all trips. |
The function calls specific sub-functions based on the selected method:
- "by.route": Calculates average distances per route.
- "by.trip": Calculate distances per trip.
- "detailed": Calculates detailed stop-to-stop distances within each route. Note that this method may be slow for large datasets.
If an invalid 'method' is provided, the function defaults to '"by.route"' and issues a warning.
A data frame with calculated distances based on the specified method:
Returns a summary with columns: 'route_id', 'trips', 'average.distance', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'route_id', 'trip_id', 'distance', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'shape_id', 'from_stop_id', 'to_stop_id', and 'distance'.
[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_servicepattern()]
# Calculate average route distances distances_by_route <- get_distances(gtfs = for_rail_gtfs, method = "by.route", trips = 'all') # Calculate distances by trip distances_by_trip <- get_distances(gtfs = for_rail_gtfs, method = "by.trip", trips = 'all') # Calculate detailed distances between stops detailed_distances <- get_distances(gtfs = for_rail_gtfs, method = "detailed", trips = 'all')# Calculate average route distances distances_by_route <- get_distances(gtfs = for_rail_gtfs, method = "by.route", trips = 'all') # Calculate distances by trip distances_by_trip <- get_distances(gtfs = for_rail_gtfs, method = "by.trip", trips = 'all') # Calculate detailed distances between stops detailed_distances <- get_distances(gtfs = for_rail_gtfs, method = "detailed", trips = 'all')
Calculates scheduled trip and segment durations in seconds.
get_durations(gtfs, method = "by.route", trips = "all")get_durations(gtfs, method = "by.route", trips = "all")
gtfs |
A GTFS object, ideally of class 'wizardgtfs'. If not, it will be converted. |
method |
A character string specifying the calculation method. Options include:
|
trips |
A character vector of trip IDs to consider. When set to 'all', includes all trips. |
This function calls specific sub-functions based on the selected method:
- "by.route": Calculates average durations for each route.
- "by.trip": Calculates the total duration of each trip.
- "detailed": Calculates detailed durations between consecutive stops within each trip, excluding dwell times.
If an invalid 'method' is specified, the function defaults to '"by.route"' and provides a warning.
A data frame containing trip durations based on the specified method:
Includes dwell from first departure to final arrival.
Includes dwell from first departure to final arrival.
It does not include dwell times. Returns a data frame with columns: 'route_id', 'trip_id', 'hour', 'from_stop_id', 'to_stop_id', 'duration', 'service_pattern', and 'pattern_frequency'.
[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_servicepattern()]
# Calculate average route durations durations_by_route <- get_durations(gtfs = for_rail_gtfs, method = "by.route", trips = 'all') # Calculate trip durations durations_by_trip <- get_durations(gtfs = for_rail_gtfs, method = "by.trip", trips = 'all') # Calculate detailed durations between stops detailed_durations <- get_durations(gtfs = for_rail_gtfs, method = "detailed", trips = 'all')# Calculate average route durations durations_by_route <- get_durations(gtfs = for_rail_gtfs, method = "by.route", trips = 'all') # Calculate trip durations durations_by_trip <- get_durations(gtfs = for_rail_gtfs, method = "by.trip", trips = 'all') # Calculate detailed durations between stops detailed_durations <- get_durations(gtfs = for_rail_gtfs, method = "detailed", trips = 'all')
The 'get_dwelltimes' function calculates dwell times within a 'wizardgtfs' object using different methods. Depending on the selected 'method', it can provide average dwell times per route, per trip, by hour, or detailed dwell times at each stop.
get_dwelltimes(gtfs, max.dwelltime = 90, method = "by.route")get_dwelltimes(gtfs, max.dwelltime = 90, method = "by.route")
gtfs |
A GTFS object, ideally of class 'wizardgtfs'. If not, it will be converted. |
max.dwelltime |
Numeric. The maximum allowable dwell time (in seconds). Dwell times exceeding this value are excluded from the calculations. Defaults to 90 seconds. |
method |
A character string specifying the calculation method. Options include:
|
This function calls specific sub-functions based on the selected method:
- "by.hour": Calculates the average dwell time for each hour of the day.
- "by.route": Calculates average dwell times across each route.
- "by.trip": Calculates the mean dwell time for each trip.
- "detailed": Calculates departure minus arrival at each stop call.
If an invalid 'method' is specified, the function defaults to '"by.route"' and provides a warning.
A data frame containing dwell times based on the specified method:
Returns a data frame with columns: 'hour', 'trips', 'average.dwelltime', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'route_id', 'trips', 'average.dwelltime', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'route_id', 'trip_id', 'average.dwelltime', 'service_pattern', and 'pattern_frequency'.
Returns a data frame with columns: 'route_id', 'trip_id', 'stop_id', 'hour', 'dwell_time', 'service_pattern', and 'pattern_frequency'.
[GTFSwizard::as_wizardgtfs()], [GTFSwizard::get_servicepattern()]
# Calculate dwell times by hour dwelltimes_by_hour <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 120, method = "by.hour") # Calculate dwell times by route dwelltimes_by_route <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 90, method = "by.route") # Calculate dwell times by trip dwelltimes_by_trip <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 45, method = "by.trip") # Calculate detailed dwell times between stops detailed_dwelltimes <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 60, method = "detailed")# Calculate dwell times by hour dwelltimes_by_hour <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 120, method = "by.hour") # Calculate dwell times by route dwelltimes_by_route <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 90, method = "by.route") # Calculate dwell times by trip dwelltimes_by_trip <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 45, method = "by.trip") # Calculate detailed dwell times between stops detailed_dwelltimes <- get_dwelltimes(gtfs = for_rail_gtfs, max.dwelltime = 60, method = "detailed")
Estimates the number of active trip instances from their first departure to final arrival. Frequency-based services are expanded from 'frequencies.txt'.
get_fleet(gtfs, method = "by.route")get_fleet(gtfs, method = "by.route")
gtfs |
A GTFS object. |
method |
One of '"by.route"', '"by.hour"', '"peak"', or '"detailed"'. |
A tibble containing fleet estimates by the selected grouping and service pattern. GTFS times beyond 24 hours remain in the following service day rather than being wrapped.
get_fleet(for_rail_gtfs, "by.route") get_fleet(for_rail_gtfs, "by.hour")get_fleet(for_rail_gtfs, "by.route") get_fleet(for_rail_gtfs, "by.hour")
Counts trip departures by route, shape, stop, or hour. Trips referenced by ‘frequencies.txt' are expanded using the period’s inclusive 'start_time', exclusive 'end_time', and 'headway_secs', as required by GTFS.
get_frequency(gtfs, method = "by.route")get_frequency(gtfs, method = "by.route")
gtfs |
A GTFS object. |
method |
One of '"by.route"', '"by.shape"', '"by.stop"', or '"detailed"'. |
A tibble containing the selected identifiers, frequency, service pattern, and number of dates represented by the pattern.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/#frequenciestxt)
[GTFSwizard::get_headways()]
get_frequency(for_rail_gtfs, "by.route") get_frequency(for_rail_gtfs, "detailed")get_frequency(for_rail_gtfs, "by.route") get_frequency(for_rail_gtfs, "detailed")
Calculates elapsed minutes between successive service instances. Frequency based trips are expanded according to 'frequencies.txt'.
get_headways(gtfs, method = "by.route")get_headways(gtfs, method = "by.route")
gtfs |
A GTFS object. |
method |
One of '"by.route"', '"by.hour"', '"by.trip"', '"by.stop"', '"by.shape"', or '"detailed"'. |
Route, hour, and trip methods compare first departures. Stop and detailed methods compare arrivals at the same stop, route, direction, and service pattern. The first service instance in each group has no headway and is omitted.
A tibble. Headway values are always returned in 'headway_minutes'; 'valid_trips' is the number of intervals summarized.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/#frequenciestxt)
[GTFSwizard::get_frequency()]
get_headways(for_rail_gtfs, "by.route") get_headways(for_rail_gtfs, "by.hour")get_headways(for_rail_gtfs, "by.route") get_headways(for_rail_gtfs, "by.hour")
Identify Stops Serving Multiple Routes
get_hubs(gtfs)get_hubs(gtfs)
gtfs |
A GTFS object. |
A WGS84 'sf' object with one row per served stop, list-columns 'trip_id' and 'route_id', counts 'n_trip' and 'n_routes', and point geometry.
[GTFSwizard::plot_hubs()], [GTFSwizard::get_stops_sf()]
get_hubs(for_rail_gtfs)get_hubs(for_rail_gtfs)
Groups 'service_id' values that operate on exactly the same set of dates.
get_servicepattern(gtfs)get_servicepattern(gtfs)
gtfs |
A GTFS object. |
A tibble with one row per 'service_id', its 'service_pattern', and 'pattern_frequency', the number of active dates in that pattern. Pattern numbers are ordered from most to least frequent.
[GTFSwizard::filter_servicepattern()]
get_servicepattern(for_rail_gtfs)get_servicepattern(for_rail_gtfs)
Builds one shape for each unique ordered stop pattern and assigns it to the corresponding trips.
get_shapes(gtfs)get_shapes(gtfs)
gtfs |
A GTFS object. |
Consecutive stop coordinates are connected directly. The result is useful for visualization and approximate distance analysis, but it is not a map-matched representation of the vehicle path.
A 'wizardgtfs' object with a new 'shapes' table and updated 'trips$shape_id'.
[GTFSwizard::get_shapes_sf()], [GTFSwizard::get_shapes_df()]
gtfs_with_shapes <- get_shapes(for_rail_gtfs)gtfs_with_shapes <- get_shapes(for_rail_gtfs)
Convert Shape Geometries to a GTFS Shapes Table
get_shapes_df(shape)get_shapes_df(shape)
shape |
An 'sf' object with a 'shape_id' field and line geometries. |
Distances are geodesic approximations between consecutive coordinates. GTFS permits any consistent distance unit; this function uses meters.
A tibble containing 'shape_id', WGS84 point coordinates, 'shape_pt_sequence', and cumulative 'shape_dist_traveled' in meters.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/#shapestxt)
[GTFSwizard::get_shapes_sf()], [GTFSwizard::get_shapes()]
shapes_sf <- get_shapes_sf(for_rail_gtfs)$shapes shapes_df <- get_shapes_df(shapes_sf)shapes_sf <- get_shapes_sf(for_rail_gtfs)$shapes shapes_df <- get_shapes_df(shapes_sf)
Convert GTFS Shapes to Simple Features
get_shapes_sf(gtfs)get_shapes_sf(gtfs)
gtfs |
A GTFS object or a 'shapes' data frame. |
For a data frame, one WGS84 'LINESTRING' feature per 'shape_id'. For a GTFS object, the same object with its 'shapes' table replaced by that 'sf' object. If present, 'shape_dist_traveled' is summarized as its maximum value for each shape.
[GTFSwizard::get_shapes_df()], [GTFSwizard::get_shapes()]
gtfs_sf <- get_shapes_sf(for_rail_gtfs) shapes_sf <- get_shapes_sf(for_rail_gtfs$shapes)gtfs_sf <- get_shapes_sf(for_rail_gtfs) shapes_sf <- get_shapes_sf(for_rail_gtfs$shapes)
Combines distance in meters and duration in seconds to calculate kilometers per hour.
get_speeds(gtfs, method = "by.route", trips = "all")get_speeds(gtfs, method = "by.route", trips = "all")
gtfs |
A GTFS object. |
method |
One of '"by.route"', '"by.trip"', or '"detailed"'. |
trips |
Character trip IDs or '"all"'. |
Detailed distances are straight-line geodesic distances between stops. Route and trip distances follow 'shapes.txt', or inferred straight-line shapes if the feed has none.
A tibble with 'average.speed' for route and trip methods, or segment-level 'speed' for the detailed method.
[GTFSwizard::get_distances()], [GTFSwizard::get_durations()]
get_speeds(for_rail_gtfs, "by.route") get_speeds(for_rail_gtfs, "by.trip")get_speeds(for_rail_gtfs, "by.route") get_speeds(for_rail_gtfs, "by.trip")
Convert GTFS Stops to Simple Features
get_stops_sf(gtfs)get_stops_sf(gtfs)
gtfs |
A GTFS object or a 'stops' data frame. |
For a data frame, a WGS84 point 'sf' object. For a GTFS object, the same object with its 'stops' table converted to 'sf'.
gtfs_sf <- get_stops_sf(for_rail_gtfs) stops_sf <- get_stops_sf(for_rail_gtfs$stops)gtfs_sf <- get_stops_sf(for_rail_gtfs) stops_sf <- get_stops_sf(for_rail_gtfs$stops)
Selects a UTM zone from the geographic centroid, or a polar stereographic CRS outside UTM's latitude range.
latlon2epsg(sf_obj)latlon2epsg(sf_obj)
sf_obj |
An 'sf' or 'sfc' object with a defined CRS. |
The input transformed to EPSG 326xx/327xx, EPSG 3413, or EPSG 3031.
[sf::st_transform()]
shapes <- get_shapes_sf(for_rail_gtfs)$shapes metric_shapes <- latlon2epsg(shapes)shapes <- get_shapes_sf(for_rail_gtfs)$shapes metric_shapes <- latlon2epsg(shapes)
Combines two feeds table by table. By default, all identifiers and their foreign-key references receive feed-specific suffixes, preventing accidental collisions.
merge_gtfs(gtfs.x, gtfs.y, suffix = TRUE)merge_gtfs(gtfs.x, gtfs.y, suffix = TRUE)
gtfs.x, gtfs.y
|
GTFS objects. |
suffix |
Logical. Append '.x' and '.y' to identifiers when 'TRUE'. |
Standard references in routes, trips, stop times, shapes, calendars, frequencies, transfers, pathways, fare tables, networks, and booking rules are updated together. Non-standard tables are row-bound without identifier rewriting.
A validated 'wizardgtfs' object.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/)
merged <- merge_gtfs(for_rail_gtfs, for_rail_gtfs, suffix = TRUE)merged <- merge_gtfs(for_rail_gtfs, for_rail_gtfs, suffix = TRUE)
Creates a calendar heatmap of scheduled trips by service date.
plot_calendar(gtfs, ncol = 4, facet_by_year = FALSE)plot_calendar(gtfs, ncol = 4, facet_by_year = FALSE)
gtfs |
A GTFS object. |
ncol |
Number of facet columns when 'facet_by_year = FALSE'. |
facet_by_year |
Logical. Arrange years in rows and months in columns. |
A 'ggplot' object.
[GTFSwizard::get_servicepattern()]
plot_calendar(for_rail_gtfs, ncol = 4)plot_calendar(for_rail_gtfs, ncol = 4)
Plot High-Frequency Corridors
plot_corridor(gtfs, i = 0.01, min.length = 1500)plot_corridor(gtfs, i = 0.01, min.length = 1500)
gtfs |
A GTFS object. |
i |
Proportion of highest-frequency segments to retain. |
min.length |
Minimum corridor length in meters. |
A 'ggplot' map.
[GTFSwizard::get_corridor()]
Shows the distribution and weighted mean of scheduled trip departures by hour. Service-pattern date counts provide the weights.
plot_frequency(gtfs)plot_frequency(gtfs)
gtfs |
A GTFS object. |
A 'ggplot' object.
[GTFSwizard::get_frequency()]
plot_frequency(for_rail_gtfs)plot_frequency(for_rail_gtfs)
Plot System Headway by Hour
plot_headways(gtfs)plot_headways(gtfs)
gtfs |
A GTFS object. |
A 'ggplot' object with headway in minutes.
[GTFSwizard::get_headways()]
plot_headways(for_rail_gtfs)plot_headways(for_rail_gtfs)
Plot Transit Hubs
plot_hubs(gtfs, i = 0.05)plot_hubs(gtfs, i = 0.05)
gtfs |
A GTFS object. |
i |
Proportion of stops with the most routes to retain. |
To keep dense networks readable, at most 40 of the highest-ranked stops are drawn. Ranking uses distinct route count and then trip count.
A 'ggplot' map.
[GTFSwizard::get_hubs()]
Shows the distribution of scheduled end-to-end trip duration for the busiest routes.
plot_routeduration(gtfs, top_n = 20L)plot_routeduration(gtfs, top_n = 20L)
gtfs |
A GTFS object. |
top_n |
Maximum number of routes to display. |
A 'ggplot' object. Each observation is one scheduled trip; boxes summarize duration in minutes by route.
[FTA Evaluation Introduction](https://www.transit.dot.gov/research-innovation/evaluation-introduction)
plot_routeduration(for_rail_gtfs)plot_routeduration(for_rail_gtfs)
Creates a heatmap of scheduled departures by route, hour, and service pattern. The tile fill is the number of scheduled trips.
plot_routefrequency(gtfs, route = NULL, top_n = 25L)plot_routefrequency(gtfs, route = NULL, top_n = 25L)
gtfs |
A GTFS object. |
route |
Optional character vector of route IDs. 'NULL' includes all routes after applying 'top_n'. |
top_n |
Maximum number of routes to display when 'route' is 'NULL'. |
A 'ggplot' object.
[GTFSwizard::get_frequency()]
plot_routefrequency( for_rail_gtfs, route = for_rail_gtfs$routes$route_id[1:2] )plot_routefrequency( for_rail_gtfs, route = for_rail_gtfs$routes$route_id[1:2] )
Creates a heatmap of average scheduled departures on active service dates.
plot_serviceheatmap(gtfs)plot_serviceheatmap(gtfs)
gtfs |
A GTFS object. |
A 'ggplot' object. Each tile is a weekday-hour combination and its fill is the mean number of scheduled trip departures per active date.
[GTFS Schedule Reference](https://gtfs.org/documentation/schedule/reference/)
plot_serviceheatmap(for_rail_gtfs)plot_serviceheatmap(for_rail_gtfs)
Shows the first departure and final arrival for route and service-pattern combinations. The longest and most frequently operated route-pattern combinations are retained when the feed is large.
plot_servicespan(gtfs, top_n = 30L)plot_servicespan(gtfs, top_n = 30L)
gtfs |
A GTFS object. |
top_n |
Maximum number of route-pattern combinations to display. |
A 'ggplot' object. Each horizontal line is one route and service pattern; its endpoints are scheduled clock hours.
[GTFS Routes, Stops, and Trips](https://gtfs.org/documentation/schedule/examples/routes-stops-trips/)
plot_servicespan(for_rail_gtfs)plot_servicespan(for_rail_gtfs)
Sums scheduled end-to-end trip durations for each route and service pattern.
plot_servicesupply(gtfs, top_n = 20L)plot_servicesupply(gtfs, top_n = 20L)
gtfs |
A GTFS object. |
top_n |
Maximum number of routes to display. |
A 'ggplot' object. Each bar is scheduled vehicle-hours for one route on one representative service-pattern day.
[FTA National Transit Database](https://www.transit.dot.gov/ntd)
plot_servicesupply(for_rail_gtfs)plot_servicesupply(for_rail_gtfs)
Imports a GTFS zip archive and converts it to 'wizardgtfs'.
read_gtfs(file.path, files = NULL, quiet = TRUE, ...)read_gtfs(file.path, files = NULL, quiet = TRUE, ...)
file.path |
Path to a GTFS '.zip' archive. |
files |
Optional character vector of table names without '.txt'. |
quiet |
Logical. Suppress importer messages. |
... |
Additional arguments passed to [gtfsio::import_gtfs()]. |
A validated 'wizardgtfs' object.
[GTFSwizard::write_gtfs()], [GTFSwizard::as_wizardgtfs()]
path <- tempfile(fileext = ".zip") write_gtfs(for_rail_gtfs, path) gtfs <- read_gtfs(path)path <- tempfile(fileext = ".zip") write_gtfs(for_rail_gtfs, path) gtfs <- read_gtfs(path)
Creates persistent selection metadata while leaving every GTFS table unchanged. Bare columns and computed values define groups, similarly to [dplyr::group_by()]. Logical expressions restrict the records represented by those groups.
selection(gtfs, ..., add = FALSE) unselection(gtfs)selection(gtfs, ..., add = FALSE) unselection(gtfs)
gtfs |
A GTFS object. |
... |
Unquoted grouping columns, computed grouping expressions, or logical selection expressions. Columns from 'stop_times', 'trips', 'routes', and 'stops' are available. A 'geometry' column is available for stop-based spatial predicates. |
add |
Logical. When 'TRUE', add the new grouping or selection expressions to an existing selection. When 'FALSE', replace it. |
A bare expression such as 'route_id' creates one group per route. Multiple grouping expressions create combinations, for example 'selection(gtfs, route_id, direction_id)'. Logical expressions such as 'route_id selection but do not remove rows from the GTFS feed.
Spatial expressions may use 'geometry' with ' '
The unchanged feed with class 'wizardgtfs_selected' and a 'selection' attribute. The attribute contains 'groups', 'group_vars', selected route, trip, and stop IDs, and the original expressions.
[GTFSwizard::unselection()], [dplyr::group_by()]
grouped <- selection(for_rail_gtfs, route_id, direction_id) attr(grouped, "selection")$groups selected <- selection( for_rail_gtfs, route_id, stop_id %in% for_rail_gtfs$stops$stop_id[1:3] ) bbox <- sf::st_bbox( c(xmin = -38.58, ymin = -3.81, xmax = -38.50, ymax = -3.75), crs = sf::st_crs(4326) ) spatial <- selection( for_rail_gtfs, geometry %intersects% sf::st_as_sfc(bbox) )grouped <- selection(for_rail_gtfs, route_id, direction_id) attr(grouped, "selection")$groups selected <- selection( for_rail_gtfs, route_id, stop_id %in% for_rail_gtfs$stops$stop_id[1:3] ) bbox <- sf::st_bbox( c(xmin = -38.58, ymin = -3.81, xmax = -38.50, ymax = -3.75), crs = sf::st_crs(4326) ) spatial <- selection( for_rail_gtfs, geometry %intersects% sf::st_as_sfc(bbox) )
Sets dwell time at selected trip-stop calls and propagates each change to all later times in the same trip. Arrival at the edited stop is retained.
set_dwelltime(gtfs, duration = 30, trips = "all", stops = "all")set_dwelltime(gtfs, duration = 30, trips = "all", stops = "all")
gtfs |
A GTFS object. |
duration |
One non-negative dwell time in seconds. |
trips, stops
|
Character ID vectors or '"all"'. |
A modified 'wizardgtfs' object.
[GTFSwizard::edit_dwelltime()], [GTFSwizard::get_dwelltimes()]
edited <- set_dwelltime( for_rail_gtfs, duration = 30, trips = for_rail_gtfs$trips$trip_id[1:2], stops = for_rail_gtfs$stops$stop_id[1:2] )edited <- set_dwelltime( for_rail_gtfs, duration = 30, trips = for_rail_gtfs$trips$trip_id[1:2], stops = for_rail_gtfs$stops$stop_id[1:2] )
Splits each selected trip into approximately equal consecutive parts. The boundary stop is included at the end of one part and the start of the next, producing valid complete stop sequences.
split_trip(gtfs, trip, split = 1L)split_trip(gtfs, trip, split = 1L)
gtfs |
A GTFS object. |
trip |
Character vector of 'trip_id' values. |
split |
Positive integer number of split points. 'split = 1' creates two parts. |
New IDs use '.part1', '.part2', and so on. New straight-line shapes are inferred from stop coordinates for the split parts. Frequency periods are shifted by each part's offset from the original first departure. Trip-level transfers are reassigned to the part containing their transfer stop.
A modified 'wizardgtfs' object.
[GTFSwizard::get_shapes()], [GTFSwizard::merge_gtfs()]
gtfs_split <- split_trip( for_rail_gtfs, trip = for_rail_gtfs$trips$trip_id[1], split = 2 )gtfs_split <- split_trip( for_rail_gtfs, trip = for_rail_gtfs$trips$trip_id[1], split = 2 )
The 'tidy_raptor' function calculates travel times from a set of origin stops to all reachable stops within a GTFS dataset. It uses the RAPTOR (Round-Based Public Transit Routing) algorithm from the 'tidytransit' package and integrates it with the GTFSwizard framework.
tidy_raptor( gtfs, min_departure = "0:0:0", max_arrival = "23:59:59", dates = NULL, stop_ids, arrival = FALSE, time_range = 3600, max_transfers = NULL, keep = "all", filter = TRUE )tidy_raptor( gtfs, min_departure = "0:0:0", max_arrival = "23:59:59", dates = NULL, stop_ids, arrival = FALSE, time_range = 3600, max_transfers = NULL, keep = "all", filter = TRUE )
gtfs |
A GTFS object, preferably of class 'wizardgtfs'. If not, the function will attempt to convert it using 'GTFSwizard::as_wizardgtfs()'. |
min_departure |
A string representing the earliest departure time, in "HH:MM:SS" format. Defaults to '"0:0:0"'. |
max_arrival |
A string representing the latest arrival time, in "HH:MM:SS" format. Defaults to '"23:59:59"'. |
dates |
A date (in '"YYYY-MM-DD"' format) to filter the GTFS dataset to specific calendar days. Defaults to 'NULL', meaning the furthest date. |
stop_ids |
A character vector of stop IDs from where journeys should start (or end, if 'arrival = TRUE'). |
arrival |
Logical. If 'FALSE' (default), journeys start from 'stop_ids'. If 'TRUE', journeys end at 'stop_ids'. |
time_range |
Either a range in seconds (numeric) or a vector with the minimal and maximal departure time (e.g., 'c(0, 3600)' or '"HH:MM:SS"') describing the journey window. |
max_transfers |
Maximum number of transfers allowed. Defaults to 'NULL' (no limit). |
keep |
One of '"all"', '"shortest"', '"earliest"', or '"latest"'. Determines which journeys to retain: - '"all"': All journeys are returned (default). - '"shortest"': Only journeys with the shortest travel time. - '"earliest"': Journeys arriving at stops the earliest. - '"latest"': Journeys arriving at stops the latest. |
filter |
A logical to filter for min_departure, max_arrivel, and dates. Defaults to 'TRUE'. |
A tibble containing the RAPTOR algorithm results, including:
The ID of the stop where the journey starts.
The ID of the stop where the journey ends.
Departure time from the origin stop.
Arrival time at the destination stop.
Total travel time in seconds.
Ensure that the 'stop_times' is present and correctly structured in the GTFS dataset. Time values in 'min_departure', 'max_arrival', and 'time_range' should be correctly formatted to avoid errors. 'max_arrival' must be 23:59:59 or earlier.
[tidytransit::raptor()], [GTFSwizard::as_wizardgtfs()], [GTFSwizard::filter_time()]
tidy_raptor(for_rail_gtfs, min_departure = '06:20:00', max_arrival = '09:40:00', dates = "2021-12-13", max_transfers = 2, keep = "all", stop_ids = '66')tidy_raptor(for_rail_gtfs, min_departure = '06:20:00', max_arrival = '09:40:00', dates = "2021-12-13", max_transfers = 2, keep = "all", stop_ids = '66')
Print, Summarize, and Plot 'wizardgtfs' Objects
## S3 method for class 'wizardgtfs' print(x, ..., n = 5L) ## S3 method for class 'wizardgtfs' summary(object, ...) ## S3 method for class 'summary.wizardgtfs' print(x, ...) ## S3 method for class 'wizardgtfs' plot(x, ...)## S3 method for class 'wizardgtfs' print(x, ..., n = 5L) ## S3 method for class 'wizardgtfs' summary(object, ...) ## S3 method for class 'summary.wizardgtfs' print(x, ...) ## S3 method for class 'wizardgtfs' plot(x, ...)
x, object
|
A 'wizardgtfs' object or its summary. |
... |
Additional arguments passed to print methods. |
n |
Number of rows shown per GTFS table. |
'print()' returns 'x' invisibly; 'summary()' returns a 'summary.wizardgtfs' object; 'plot()' returns a 'ggplot' object.
Exports a GTFS object to a zip archive. Internal 'dates_services' data are omitted, GTFS dates use 'YYYYMMDD', and spatial stops/shapes are converted back to standard text-table columns.
write_gtfs(gtfs, zipfile, ...)write_gtfs(gtfs, zipfile, ...)
gtfs |
A GTFS object. |
zipfile |
Output '.zip' path. |
... |
Additional arguments passed to the format-specific writer. |
The normalized output path, invisibly.
[GTFSwizard::read_gtfs()]
path <- tempfile(fileext = ".zip") write_gtfs(for_rail_gtfs, path)path <- tempfile(fileext = ".zip") write_gtfs(for_rail_gtfs, path)