get_hubs: Identify Transit Hubs

View source: R/get_hubs.R

get_hubsR Documentation

Identify Transit Hubs

Description

The 'get_hubs' function identifies transit hubs from a GTFS dataset by calculating the number of trips and unique routes served by each stop. It returns a spatial object with metadata for each hub, allowing for further analysis or visualization.

Usage

get_hubs(gtfs)

Arguments

gtfs

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

Details

The function performs the following steps:

  1. Extracts 'stop_id' and 'trip_id' pairs from the 'stop_times' table.

  2. Joins this data with the 'trips' table to associate 'route_id' with each trip.

  3. Groups by 'stop_id' to compute the number of trips ('n_trip') and unique routes ('n_route') per stop.

  4. Joins the resulting data with the spatial geometry of stops, transforming it into an 'sf' object.

  5. Sorts the hubs by the number of unique routes ('n_routes') in descending order.

Value

An 'sf' object containing the following columns:

stop_id

The unique identifier for each stop.

trip_id

A list of trip IDs associated with the stop.

route_id

A list of unique route IDs associated with the stop.

n_trip

The total number of trips that pass through the stop.

n_routes

The total number of unique routes that pass through the stop.

geometry

The spatial location of the stop as an 'sf' point object.

Note

The function uses 'sf' for spatial data manipulation. Ensure that the GTFS dataset includes the 'stop_times', 'trips', and 'stops' tables.

See Also

[GTFSwizard::get_stops_sf()], [GTFSwizard::as_wizardgtfs()]

Examples

# Identify hubs in a GTFS dataset
get_hubs(for_rail_gtfs)


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