Skip to content

Commit b495a41

Browse files
authored
Merge pull request #100 from NatLabRockies/yep/island-detection
Island detection algorithm
2 parents 4f4c544 + 80466bc commit b495a41

File tree

9 files changed

+508
-10
lines changed

9 files changed

+508
-10
lines changed

configuration/bambam-omf/travel-mode-filter.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,9 @@
3939
{ "type": "access_mode", "modes": ["motor_vehicle", "car", "truck", "motorcycle"] }
4040
]
4141
}
42-
]
42+
],
43+
"island_algorithm_configuration": {
44+
"min_distance": 2,
45+
"distance_unit": "miles"
46+
}
4347
}

rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ gtfs-structures = "0.43.0"
3838
h3o = { version = "0.8.0", features = ["serde", "geo"] }
3939
hex = "0.4.3"
4040
humantime = "2.3.0"
41+
indexmap = "2.12.0"
4142
inventory = { version = "0.3.21" }
4243
itertools = { version = "0.14.0" }
4344
jsonpath-rust = { version = "1.0.4" }

rust/bambam-omf/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ geozero = { workspace = true }
3636
hex = { workspace = true }
3737
itertools = { workspace = true }
3838
kdam = { workspace = true }
39+
indexmap = { workspace = true }
3940
log = { workspace = true }
4041
object_store = { workspace = true }
4142
opening-hours-syntax = { workspace = true }

rust/bambam-omf/src/app/network.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::path::Path;
22

3+
use routee_compass_core::model::unit::DistanceUnit;
34
use serde::{Deserialize, Serialize};
45

56
use crate::{
@@ -17,6 +18,7 @@ use crate::{
1718
pub struct NetworkEdgeListConfiguration {
1819
pub mode: String,
1920
pub filter: Vec<TravelModeFilter>,
21+
pub island_algorithm_config: Option<IslandDetectionAlgorithmConfiguration>,
2022
}
2123

2224
impl From<&NetworkEdgeListConfiguration> for SegmentAccessRestrictionWhen {
@@ -33,13 +35,20 @@ impl From<&NetworkEdgeListConfiguration> for SegmentAccessRestrictionWhen {
3335
}
3436
}
3537

38+
#[derive(Serialize, Deserialize, Clone, Debug)]
39+
pub struct IslandDetectionAlgorithmConfiguration {
40+
pub min_distance: f64,
41+
pub distance_unit: DistanceUnit,
42+
}
43+
3644
/// runs an OMF network import using the provided configuration.
3745
pub fn run(
3846
bbox: Option<&CliBoundingBox>,
3947
modes: &[NetworkEdgeListConfiguration],
4048
output_directory: &Path,
4149
local_source: Option<&Path>,
4250
write_json: bool,
51+
island_detection_configuration: Option<IslandDetectionAlgorithmConfiguration>,
4352
) -> Result<(), OvertureMapsCollectionError> {
4453
let collection: TransportationCollection = match local_source {
4554
Some(src_path) => read_local(src_path),
@@ -51,7 +60,8 @@ pub fn run(
5160
collection.to_json(output_directory)?;
5261
}
5362

54-
let vectorized_graph = OmfGraphVectorized::new(&collection, modes)?;
63+
let vectorized_graph =
64+
OmfGraphVectorized::new(&collection, modes, island_detection_configuration)?;
5565
vectorized_graph.write_compass(output_directory, true)?;
5666

5767
Ok(())

rust/bambam-omf/src/app/omf_app.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use config::{Config, File};
55
use serde::{Deserialize, Serialize};
66

77
use crate::{
8-
app::{cli_bbox::parse_bbox, network::NetworkEdgeListConfiguration, CliBoundingBox},
8+
app::{
9+
cli_bbox::parse_bbox,
10+
network::{IslandDetectionAlgorithmConfiguration, NetworkEdgeListConfiguration},
11+
CliBoundingBox,
12+
},
913
collection::OvertureMapsCollectionError,
1014
};
1115

@@ -73,12 +77,29 @@ impl OmfOperation {
7377
);
7478
OvertureMapsCollectionError::InvalidUserInput(msg)
7579
})?;
80+
let island_algorithm_configuration = config
81+
.get::<Option<IslandDetectionAlgorithmConfiguration>>(
82+
"island_algorithm_configuration",
83+
)
84+
.map_err(|e| {
85+
let msg = format!(
86+
"error reading 'island_algorithm_configuration' key in '{configuration_file}': {e}"
87+
);
88+
OvertureMapsCollectionError::InvalidUserInput(msg)
89+
})?;
7690
let outdir = match output_directory {
7791
Some(out) => Path::new(out),
7892
None => Path::new(""),
7993
};
8094
let local = local_source.as_ref().map(Path::new);
81-
crate::app::network::run(bbox.as_ref(), &network_config, outdir, local, *store_raw)
95+
crate::app::network::run(
96+
bbox.as_ref(),
97+
&network_config,
98+
outdir,
99+
local,
100+
*store_raw,
101+
island_algorithm_configuration,
102+
)
82103
}
83104
}
84105
}

0 commit comments

Comments
 (0)