Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to skip shapes reading #151

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gtfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
/// ```
Expand Down
21 changes: 18 additions & 3 deletions src/gtfs_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -36,12 +37,15 @@ 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,
/// If a an enumeration has un unknown value, should we use the default value
/// [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 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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading