GTFS Model
The General Transit Feed Specification (GTFS) is a commonly used model to represent public transit data.
This crates brings serde structures of this model and helpers to read GTFS archives.
Using
This crates has 2 main entry-points.
Gtfs
The most common one is to create a gtfs_structures::Gtfs
:
// Gtfs::new will try to guess if you provide a path, a local zip file or a remote zip file.
// You can also use Gtfs::from_path or Gtfs::from_url
let gtfs = new?;
println!;
// This structure is the easiest to use as the collections are `HashMap`,
// thus you can access an object by its id.
let route_1 = gtfs.routes.get.expect;
println!;
RawGtfs
If you want a lower level model, you can use gtfs_structures::RawGtfs
:
let raw_gtfs = new.expect;
for stop in raw_gtfs.stops.expect
Instead of easy to use HashMap
, each collection is a Result
with an error if something went wrong during the reading.
This makes it possible for example for a GTFS validator to display better error messages.
Feature 'read-url'
By default the feature 'read-url' is activated. It makes it possible to read a Gtfs from an url.
let gtfs = new?;
Or you can use the explicit constructor:
let gtfs = from_url?;
If you don't want the dependency to reqwest
, you can remove this feature.
Building
You need an up to date rust tool-chain (commonly installed with rustup).
Building is done with:
cargo build
You can also run the unit tests:
cargo test
And run the examples by giving their names:
cargo run --example gtfs_reading
Alternative
If you are interested in transit data, you can also use the really nice crate transit_model that can also handle GTFS data.
The price to pay is a steeper learning curve (and a documentation that could be improved :roll_eyes:), but this crate provides very nice ergonomics to handle transit data and lots of utilities like data format conversions, datasets merge, ...