From 05d093282eeccfacfb633651fed6275b1051b026 Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:10:11 -0800 Subject: [PATCH 1/3] Add ability to skip shapes reading --- src/gtfs.rs | 2 +- src/gtfs_reader.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/gtfs.rs b/src/gtfs.rs index f3964b1..99f8bbc 100644 --- a/src/gtfs.rs +++ b/src/gtfs.rs @@ -9,7 +9,7 @@ use std::sync::Arc; /// /// This structure is easier to use than the [RawGtfs] structure as some relationships are parsed to be easier to use. /// -/// If you want to configure the behaviour (e.g. skipping : [StopTime]), see [crate::GtfsReader] for more personalisation +/// If you want to configure the behaviour (e.g. skipping : [StopTime] or [Shape]), see [crate::GtfsReader] for more personalisation /// /// This is probably the entry point you want to use: /// ``` diff --git a/src/gtfs_reader.rs b/src/gtfs_reader.rs index 7c15a02..b80ff46 100644 --- a/src/gtfs_reader.rs +++ b/src/gtfs_reader.rs @@ -14,6 +14,7 @@ use std::path::Path; /// ``` ///let gtfs = gtfs_structures::GtfsReader::default() /// .read_stop_times(false) // Won’t read the stop times to save time and memory +/// .read_shapes(false) // Won’t read shapes to save time and memory /// .unkown_enum_as_default(false) // Won’t convert unknown enumerations into default (e.g. LocationType=42 considered as a stop point) /// .read("fixtures/zips/gtfs.zip")?; ///assert_eq!(0, gtfs.trips.get("trip1").unwrap().stop_times.len()); @@ -36,6 +37,9 @@ pub struct GtfsReader { /// [crate::objects::StopTime] are very large and not always needed. This allows to skip reading them #[derivative(Default(value = "true"))] pub read_stop_times: bool, + /// [crate::objects::Shape] are very large and not always needed. This allows to skip reading them + #[derivative(Default(value = "true"))] + pub read_shapes: bool, /// If a an enumeration has un unknown value, should we use the default value #[derivative(Default(value = "false"))] pub unkown_enum_as_default: bool, @@ -57,6 +61,13 @@ impl GtfsReader { self } + /// This can be useful to save time and memory with large datasets when shapes are not needed + /// Returns Self and can be chained + pub fn read_shapes(mut self, read_shapes: bool) -> Self { + self.read_shapes = read_shapes; + self + } + /// If a an enumeration has un unknown value, should we use the default value (default: false) /// /// For instance, if [crate::objects::Stop] has a [crate::objects::LocationType] with a value 42 in the GTFS @@ -290,7 +301,11 @@ impl RawGtfsReader { transfers: self.read_optional_file(&file_mapping, &mut archive, "transfers.txt"), pathways: self.read_optional_file(&file_mapping, &mut archive, "pathways.txt"), feed_info: self.read_optional_file(&file_mapping, &mut archive, "feed_info.txt"), - shapes: self.read_optional_file(&file_mapping, &mut archive, "shapes.txt"), + shapes: if self.reader.read_shapes { + self.read_optional_file(&file_mapping, &mut archive, "shapes.txt") + } else { + Some(Ok(Vec::new())) + }, read_duration: Utc::now().signed_duration_since(now).num_milliseconds(), files, source_format: crate::SourceFormat::Zip, From c5ce79543eb1dcdf71d40550a5ecdffc5a993d30 Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:16:04 -0800 Subject: [PATCH 2/3] Fix mispelling in GTFS reader --- src/gtfs_reader.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gtfs_reader.rs b/src/gtfs_reader.rs index b80ff46..1511282 100644 --- a/src/gtfs_reader.rs +++ b/src/gtfs_reader.rs @@ -40,12 +40,12 @@ pub struct GtfsReader { /// [crate::objects::Shape] are very large and not always needed. This allows to skip reading them #[derivative(Default(value = "true"))] pub read_shapes: bool, - /// If a an enumeration has un unknown value, should we use the default value + /// If a an enumeration has an unknown value, should we use the default value #[derivative(Default(value = "false"))] pub unkown_enum_as_default: bool, /// Avoid trimming the fields /// - /// It is quite time consumming + /// It is quite time consuming /// If performance is an issue, and if your data is high quality, you can switch it off #[derivative(Default(value = "true"))] pub trim_fields: bool, From dd84af5339953afe1577b20a26d1fb8fc2c69648 Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Mon, 18 Dec 2023 17:53:51 -0800 Subject: [PATCH 3/3] Increase version number to 0.39.0 for release asap --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4876fe2..bcb175a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "Read GTFS (public transit timetables) files" name = "gtfs-structures" -version = "0.38.0" +version = "0.39.0" authors = ["Tristram Gräbener ", "Antoine Desbordes "] repository = "https://github.com/rust-transit/gtfs-structure" license = "MIT"