gtfs/static/query
GTFS Static Feed Query Utilities
Provides convenient query functions for accessing and filtering GTFS feed data. These functions complement the basic getters in the feed module with more advanced query capabilities.
Example
import gtfs/static/feed
import gtfs/static/query
pub fn main() {
// Load a feed
let assert Ok(my_feed) = feed.load("path/to/gtfs.zip")
// Index the feed for fast lookups
let indexed = query.index_feed(my_feed)
// Fast O(1) lookup
let stop = query.get_stop(indexed, "STOP_123")
}
Types
Type alias for Date from common types
pub type Date =
types.Date
Get basic statistics about the feed
pub type FeedStats {
FeedStats(
agency_count: Int,
route_count: Int,
stop_count: Int,
trip_count: Int,
stop_time_count: Int,
shape_point_count: Int,
)
}
Constructors
-
FeedStats( agency_count: Int, route_count: Int, stop_count: Int, trip_count: Int, stop_time_count: Int, shape_point_count: Int, )
Indexed feed for O(1) lookups by ID
pub type IndexedFeed {
IndexedFeed(
feed: feed.Feed,
stops_by_id: dict.Dict(String, types.Stop),
routes_by_id: dict.Dict(String, types.Route),
trips_by_id: dict.Dict(String, types.Trip),
agencies_by_id: dict.Dict(String, types.Agency),
stop_times_by_trip: dict.Dict(String, List(types.StopTime)),
stop_times_by_stop: dict.Dict(String, List(types.StopTime)),
trips_by_route: dict.Dict(String, List(types.Trip)),
shapes_by_id: dict.Dict(String, List(types.ShapePoint)),
)
}
Constructors
-
IndexedFeed( feed: feed.Feed, stops_by_id: dict.Dict(String, types.Stop), routes_by_id: dict.Dict(String, types.Route), trips_by_id: dict.Dict(String, types.Trip), agencies_by_id: dict.Dict(String, types.Agency), stop_times_by_trip: dict.Dict(String, List(types.StopTime)), stop_times_by_stop: dict.Dict(String, List(types.StopTime)), trips_by_route: dict.Dict(String, List(types.Trip)), shapes_by_id: dict.Dict(String, List(types.ShapePoint)), )
Values
pub fn get_accessible_stops(feed: feed.Feed) -> List(types.Stop)
Get all wheelchair accessible stops
pub fn get_active_services(
feed: feed.Feed,
date: types.Date,
) -> List(String)
Get all service IDs active on a given date
pub fn get_active_trips(
feed: feed.Feed,
date: types.Date,
) -> List(types.Trip)
Get all trips active on a given date
pub fn get_agency(
indexed: IndexedFeed,
agency_id: String,
) -> option.Option(types.Agency)
Get an agency by ID using indexed lookup (O(1))
pub fn get_rail_routes(feed: feed.Feed) -> List(types.Route)
Get all rail routes (includes subway, rail, tram)
pub fn get_route(
indexed: IndexedFeed,
route_id: String,
) -> option.Option(types.Route)
Get a route by ID using indexed lookup (O(1))
pub fn get_route_for_trip(
feed: feed.Feed,
trip: types.Trip,
) -> option.Option(types.Route)
Get the route for a trip
pub fn get_routes_by_type(
feed: feed.Feed,
route_type: types.RouteType,
) -> List(types.Route)
Get all routes of a specific type
pub fn get_shape(
indexed: IndexedFeed,
shape_id: String,
) -> List(types.ShapePoint)
Get shape points for a shape ID using indexed lookup (O(1))
pub fn get_stations(feed: feed.Feed) -> List(types.Stop)
Get all parent stations (location_type = 1)
pub fn get_stop(
indexed: IndexedFeed,
stop_id: String,
) -> option.Option(types.Stop)
Get a stop by ID using indexed lookup (O(1))
pub fn get_stop_times_at_stop(
indexed: IndexedFeed,
stop_id: String,
) -> List(types.StopTime)
Get all stop times at a stop using indexed lookup (O(1))
pub fn get_stop_times_for_trip(
indexed: IndexedFeed,
trip_id: String,
) -> List(types.StopTime)
Get all stop times for a trip using indexed lookup (O(1))
pub fn get_stops_for_trip(
feed: feed.Feed,
trip_id: String,
) -> List(types.Stop)
Get all stops visited by a trip (in order)
pub fn get_stops_in_station(
feed: feed.Feed,
station_id: String,
) -> List(types.Stop)
Get all stops belonging to a parent station
pub fn get_trip(
indexed: IndexedFeed,
trip_id: String,
) -> option.Option(types.Trip)
Get a trip by ID using indexed lookup (O(1))
pub fn get_trips_by_direction(
feed: feed.Feed,
direction: Int,
) -> List(types.Trip)
Get all trips in a direction (0 or 1)
pub fn get_trips_on_route(
indexed: IndexedFeed,
route_id: String,
) -> List(types.Trip)
Get all trips on a route using indexed lookup (O(1))
pub fn index_feed(feed: feed.Feed) -> IndexedFeed
Create an indexed feed for faster lookups
pub fn is_service_active(
feed: feed.Feed,
service_id: String,
date: types.Date,
) -> Bool
Check if a service is active on a given date