Skip to content

Commit

Permalink
Merge pull request #151 from kylerchin/main
Browse files Browse the repository at this point in the history
Add ability to skip shapes reading
  • Loading branch information
antoine-de authored Dec 19, 2023
2 parents 3906ff6 + dd84af5 commit ee87da9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>", "Antoine Desbordes <[email protected]>"]
repository = "https://github.com/rust-transit/gtfs-structure"
license = "MIT"
Expand Down
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

0 comments on commit ee87da9

Please sign in to comment.