Skip to content

Commit b1fb907

Browse files
committed
add a complete example on stops handling
1 parent 95d1614 commit b1fb907

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

examples/gtfs_reader.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ fn main() {
22
/* Gtfs::new will try to guess if you provide a path, a local zip file or a remote zip file.
33
You can also use Gtfs::from_path, Gtfs::from_url
44
*/
5-
let gtfs = gtfs_structures::GtfsReader::default()
6-
.read_stop_times(false)
5+
let mut gtfs = gtfs_structures::GtfsReader::default()
6+
.read_stop_times(true)
77
.read("fixtures/basic")
88
.expect("impossible to read gtfs");
99
gtfs.print_stats();
@@ -12,4 +12,30 @@ fn main() {
1212

1313
let route_1 = gtfs.routes.get("1").expect("no route 1");
1414
println!("{}: {:?}", route_1.short_name, route_1);
15+
16+
// you can access a stop by a &str
17+
let _ = gtfs
18+
.get_stop_by_raw_id("stop1")
19+
.expect("unable to find stop Stop Area");
20+
21+
let trip = gtfs.trips.get("trip1").expect("no route 1");
22+
let stop_id: &gtfs_structures::Id<gtfs_structures::Stop> =
23+
&trip.stop_times.first().expect("no stoptimes").stop;
24+
25+
// or with a typed id if you have one
26+
27+
// if no stops have been removed from the gtfs, you can safely access the stops by it's id
28+
let s = &gtfs.stops[stop_id];
29+
println!("stop name: {}", &s.name);
30+
31+
// if some removal have been done, you can also you those method to get an Option<Stop>
32+
let s = gtfs.get_stop(stop_id).expect("this stop should exists");
33+
println!("stop description: {}", &s.description);
34+
35+
// or you can access it via `stops.get`
36+
let s = gtfs.stops.get(stop_id).expect("this stop should exists");
37+
println!("stop location type: {:?}", &s.location_type);
38+
39+
let mut s = gtfs.stops.get_mut(stop_id).expect("this stop should exists");
40+
s.code = Some("code".into());
1541
}

fixtures/basic/stops.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
stop_id,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,wheelchair_boarding
22
stop1,"Stop Area",, 48.796058 ,2.449386,,,1,,
3-
stop2,"StopPoint",,48.796058,2.449386,,,,,
3+
stop2,"StopPoint",some description,48.796058,2.449386,,,,,
44
stop3,"Stop Point child of 1",,48.796058,2.449386,,,0,1,
55
stop4,"StopPoint2",,48.796058,2.449386,,,,,
66
stop5,"Stop Point child of 1 bis",,48.796058,2.449386,,,0,1,

0 commit comments

Comments
 (0)