gtfs/static/feed
GTFS Static Feed
This module provides functionality to load and work with complete GTFS Static feeds from ZIP archives or directories.
Example
import gtfs/static/feed
import gleam/list
pub fn main() {
// Load a feed from a ZIP file
case feed.load("path/to/gtfs.zip") {
Ok(my_feed) -> {
// Access feed data
let stop_count = list.length(my_feed.stops)
}
Error(err) -> {
// Handle error
}
}
}
Types
A complete GTFS Static feed containing all parsed data
pub type Feed {
Feed(
agencies: List(types.Agency),
routes: List(types.Route),
trips: List(types.Trip),
stop_times: List(types.StopTime),
stops: List(types.Stop),
calendar: option.Option(List(types.Calendar)),
calendar_dates: option.Option(List(types.CalendarDate)),
feed_info: option.Option(types.FeedInfo),
levels: option.Option(List(types.Level)),
shapes: option.Option(List(types.ShapePoint)),
frequencies: option.Option(List(types.Frequency)),
transfers: option.Option(List(types.Transfer)),
pathways: option.Option(List(types.Pathway)),
fare_attributes: option.Option(List(types.FareAttribute)),
fare_rules: option.Option(List(types.FareRule)),
translations: option.Option(List(types.Translation)),
attributions: option.Option(List(types.Attribution)),
areas: option.Option(List(types.Area)),
stop_areas: option.Option(List(types.StopArea)),
networks: option.Option(List(types.Network)),
route_networks: option.Option(List(types.RouteNetwork)),
timeframes: option.Option(List(types.Timeframe)),
fare_media: option.Option(List(types.FareMedia)),
fare_products: option.Option(List(types.FareProduct)),
fare_leg_rules: option.Option(List(types.FareLegRule)),
fare_leg_join_rules: option.Option(
List(types.FareLegJoinRule),
),
fare_transfer_rules: option.Option(
List(types.FareTransferRule),
),
location_groups: option.Option(List(types.LocationGroup)),
location_group_stops: option.Option(
List(types.LocationGroupStop),
),
locations: option.Option(types.LocationsGeoJson),
booking_rules: option.Option(List(types.BookingRule)),
)
}
Constructors
-
Feed( agencies: List(types.Agency), routes: List(types.Route), trips: List(types.Trip), stop_times: List(types.StopTime), stops: List(types.Stop), calendar: option.Option(List(types.Calendar)), calendar_dates: option.Option(List(types.CalendarDate)), feed_info: option.Option(types.FeedInfo), levels: option.Option(List(types.Level)), shapes: option.Option(List(types.ShapePoint)), frequencies: option.Option(List(types.Frequency)), transfers: option.Option(List(types.Transfer)), pathways: option.Option(List(types.Pathway)), fare_attributes: option.Option(List(types.FareAttribute)), fare_rules: option.Option(List(types.FareRule)), translations: option.Option(List(types.Translation)), attributions: option.Option(List(types.Attribution)), areas: option.Option(List(types.Area)), stop_areas: option.Option(List(types.StopArea)), networks: option.Option(List(types.Network)), route_networks: option.Option(List(types.RouteNetwork)), timeframes: option.Option(List(types.Timeframe)), fare_media: option.Option(List(types.FareMedia)), fare_products: option.Option(List(types.FareProduct)), fare_leg_rules: option.Option(List(types.FareLegRule)), fare_leg_join_rules: option.Option(List(types.FareLegJoinRule)), fare_transfer_rules: option.Option(List(types.FareTransferRule)), location_groups: option.Option(List(types.LocationGroup)), location_group_stops: option.Option( List(types.LocationGroupStop), ), locations: option.Option(types.LocationsGeoJson), booking_rules: option.Option(List(types.BookingRule)), )Arguments
- agencies
-
Transit agencies (required file)
- routes
-
Routes (required file)
- trips
-
Trips (required file)
- stop_times
-
Stop times (required file)
- stops
-
Stops and stations (conditionally required - either this or locations)
- calendar
-
Weekly service schedule (conditionally required - either this or calendar_dates)
- calendar_dates
-
Service exceptions (conditionally required - either this or calendar)
- feed_info
-
Feed metadata (conditionally required if translations provided)
- levels
-
Multi-level station levels (conditionally required if pathways use levels)
- shapes
-
Shape points for trip paths (optional)
- frequencies
-
Frequency-based service (optional)
- transfers
-
Transfer rules (optional)
- pathways
-
Station pathways (optional)
- fare_attributes
-
Fare attributes - legacy v1 (optional)
- fare_rules
-
Fare rules - legacy v1 (optional)
- translations
-
Translations (optional)
- attributions
-
Attributions (optional)
- areas
-
Areas for fare calculations (optional)
- stop_areas
-
Stop-area assignments (optional)
- networks
-
Networks for fare calculations (optional)
- route_networks
-
Route-network assignments (optional)
- timeframes
-
Timeframes for fare calculations (optional)
- fare_media
-
Fare media types (optional)
- fare_products
-
Fare products (optional)
- fare_leg_rules
-
Fare leg rules (optional)
- fare_leg_join_rules
-
Fare leg join rules (optional)
- fare_transfer_rules
-
Fare transfer rules (optional)
- location_groups
-
Location groups for flexible routing (optional)
- location_group_stops
-
Location group stop assignments (optional)
- locations
-
GeoJSON locations for flexible routing (optional)
- booking_rules
-
Booking rules for flexible service (optional)
Errors that can occur when loading a feed
pub type LoadError {
FileError(path: String, reason: String)
CsvParseError(file: String, error: csv.ParseError)
MissingRequiredFile(filename: String)
InvalidFeed(reason: String)
ZipError(error: zip.ZipError)
GeoJsonError(file: String, reason: String)
ValidationErrors(errors: List(validation.ValidationError))
MultipleErrors(errors: List(LoadError))
}
Constructors
-
FileError(path: String, reason: String)File system error
-
CsvParseError(file: String, error: csv.ParseError)CSV parsing error
-
MissingRequiredFile(filename: String)Required file is missing
-
InvalidFeed(reason: String)Invalid feed structure
-
ZipError(error: zip.ZipError)ZIP archive error
-
GeoJsonError(file: String, reason: String)GeoJSON parsing error
-
ValidationErrors(errors: List(validation.ValidationError))Validation errors (when validation is enabled)
-
MultipleErrors(errors: List(LoadError))Multiple parse errors (when error recovery is enabled)
Options for loading a feed
pub type LoadOptions {
LoadOptions(
validate: Bool,
collect_errors: Bool,
streaming: Bool,
)
}
Constructors
-
LoadOptions( validate: Bool, collect_errors: Bool, streaming: Bool, )Arguments
- validate
-
Whether to validate the feed after loading (default: True)
- collect_errors
-
Whether to collect all errors instead of failing on first (default: False)
- streaming
-
Whether to use streaming/lazy loading for large feeds (default: False)
Values
pub fn collect_validation_errors(
feed: Feed,
) -> List(validation.ValidationError)
Collect all validation errors from a feed without failing
pub fn error_collection_options() -> LoadOptions
Load options with error collection
pub fn get_agency(
feed: Feed,
agency_id: String,
) -> option.Option(types.Agency)
Get an agency by ID
pub fn get_calendar(
feed: Feed,
service_id: String,
) -> option.Option(types.Calendar)
Get calendar entry by service_id
pub fn get_calendar_dates(
feed: Feed,
service_id: String,
) -> List(types.CalendarDate)
Get all calendar dates for a service_id
pub fn get_fare_attribute(
feed: Feed,
fare_id: String,
) -> option.Option(types.FareAttribute)
Get fare attributes by ID
pub fn get_fare_rules(
feed: Feed,
fare_id: String,
) -> List(types.FareRule)
Get fare rules for a fare ID
pub fn get_frequencies_for_trip(
feed: Feed,
trip_id: String,
) -> List(types.Frequency)
Get all frequencies for a trip
pub fn get_level(
feed: Feed,
level_id: String,
) -> option.Option(types.Level)
Get a level by ID
pub fn get_pathways_from_stop(
feed: Feed,
stop_id: String,
) -> List(types.Pathway)
Get all pathways from a stop
pub fn get_route(
feed: Feed,
route_id: String,
) -> option.Option(types.Route)
Get a route by ID
pub fn get_routes_for_agency(
feed: Feed,
agency_id: String,
) -> List(types.Route)
Get all routes for an agency
pub fn get_shape_points(
feed: Feed,
shape_id: String,
) -> List(types.ShapePoint)
Get all shape points for a shape, sorted by sequence
pub fn get_stop(
feed: Feed,
stop_id: String,
) -> option.Option(types.Stop)
Get a stop by ID
pub fn get_stop_times_for_stop(
feed: Feed,
stop_id: String,
) -> List(types.StopTime)
Get all stop times for a stop
pub fn get_stop_times_for_trip(
feed: Feed,
trip_id: String,
) -> List(types.StopTime)
Get all stop times for a trip, sorted by stop_sequence
pub fn get_trip(
feed: Feed,
trip_id: String,
) -> option.Option(types.Trip)
Get a trip by ID
pub fn get_trips_for_route(
feed: Feed,
route_id: String,
) -> List(types.Trip)
Get all trips for a route
pub fn load(path: String) -> Result(Feed, LoadError)
Load a GTFS feed from a path (ZIP file or directory) Automatically detects whether the path is a ZIP archive or directory
pub fn load_from_directory(
path: String,
) -> Result(Feed, LoadError)
Load a GTFS feed from a directory containing extracted files
pub fn load_from_directory_with_options(
path: String,
options: LoadOptions,
) -> Result(Feed, LoadError)
Load a GTFS feed from a directory with options
pub fn load_from_zip_with_options(
path: String,
options: LoadOptions,
) -> Result(Feed, LoadError)
Load a GTFS feed from a ZIP archive with options
pub fn load_with_options(
path: String,
options: LoadOptions,
) -> Result(Feed, LoadError)
Load a GTFS feed with custom options
pub fn no_validation_options() -> LoadOptions
Load options without validation