Skip to content

Commit 584dcae

Browse files
Merge pull request #78 from NREL/rjf/directed-graph
Rjf/directed graph
2 parents e4e3156 + a68ab28 commit 584dcae

File tree

18 files changed

+1225
-152
lines changed

18 files changed

+1225
-152
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"type": "class",
99
"classes": ["secondary", "tertiary", "residential", "living_street", "unclassified", "service", "pedestrian", "footway", "steps", "path", "track", "bridleway", "unknown"],
10-
"ignore_unset": true,
10+
"allow_unset": true,
1111
"behavior": "include"
1212
},
1313
{ "type": "access_mode", "modes": ["foot"] }
@@ -20,7 +20,7 @@
2020
{
2121
"type": "class",
2222
"classes": ["primary", "secondary", "tertiary", "residential", "living_street", "unclassified", "service", "pedestrian", "path", "track", "cycleway", "bridleway", "unknown"],
23-
"ignore_unset": true,
23+
"allow_unset": true,
2424
"behavior": "include"
2525
},
2626
{ "type": "access_mode", "modes": ["bicycle"] }
@@ -33,7 +33,7 @@
3333
{
3434
"type": "class",
3535
"classes": ["motorway", "trunk", "primary", "secondary", "tertiary", "residential", "living_street", "unclassified", "service", "unknown"],
36-
"ignore_unset": true,
36+
"allow_unset": true,
3737
"behavior": "include"
3838
},
3939
{ "type": "access_mode", "modes": ["motor_vehicle", "car", "truck", "motorcycle"] }

rust/Cargo.toml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
[workspace]
22
resolver = "2"
3-
members = ["bambam", "bambam-osm", "bambam-gtfs", "bambam-omf", "bambam-gbfs", "bambam-py"]
3+
members = [
4+
"bambam",
5+
"bambam-gbfs",
6+
"bambam-gtfs",
7+
"bambam-omf",
8+
"bambam-osm",
9+
"bambam-py",
10+
]
411

512
[workspace.dependencies]
613

14+
# third party
15+
arrow = { version = "55.0.0" }
16+
bamcensus = { version = "0.1.0" }
17+
bamcensus-acs = { version = "0.1.0" }
18+
719
# nrel
820
bamcensus-core = { version = "0.1.0" }
9-
bamcensus-acs = { version = "0.1.0" }
10-
bamcensus = { version = "0.1.0" }
1121
bamcensus-lehd = { version = "0.1.0" }
12-
routee-compass = "0.15.2"
13-
routee-compass-core = "0.15.2"
14-
routee-compass-powertrain = "0.15.2"
15-
routee-compass-py = "0.15.2"
16-
routee-compass-macros = "0.15.2"
17-
18-
# third party
19-
arrow = { version = "55.0.0" }
2022
chrono = { version = "0.4.41", features = ["serde"] }
2123
clap = { version = "4.3.19", features = ["derive"] }
2224
config = "0.15.11"
@@ -51,11 +53,16 @@ rand = "0.9.1"
5153
rayon = "1.10.0"
5254
regex = { version = "1.11.1" }
5355
reqwest = { version = "0.12.12", features = ["blocking"] }
56+
routee-compass = "0.15.2"
57+
routee-compass-core = "0.15.2"
58+
routee-compass-macros = "0.15.2"
59+
routee-compass-powertrain = "0.15.2"
60+
routee-compass-py = "0.15.2"
5461
rstar = { version = "0.12.0" }
5562
serde = { version = "1.0.160", features = ["derive"] }
56-
serde_bytes = "0.11"
57-
serde_json = { version = "1.0" }
5863
serde_arrow = { version = "0.13.7", features = ["arrow-55"] }
64+
serde_bytes = { version = "0.11.19" }
65+
serde_json = { version = "1.0" }
5966
serde_with = { version = "3.0", features = ["chrono_0_4"] }
6067
shapefile = { version = "0.7.0", features = ["geo-types"] }
6168
skiplist = "0.5.1"

rust/bambam-gbfs/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ license = "BSD-3-Clause"
66
description = "GBFS Extensions for The Behavior and Advanced Mobility Big Access Model"
77

88
[dependencies]
9+
chrono = { workspace = true }
10+
clap = { workspace = true }
911
env_logger = { workspace = true }
12+
geo = { workspace = true }
13+
humantime = { workspace = true }
14+
kdam = { workspace = true }
15+
log = { workspace = true }
16+
reqwest = { workspace = true }
1017
routee-compass-core = { workspace = true }
1118
serde = { workspace = true }
1219
serde_json = { workspace = true }
1320
serde_with = { workspace = true }
14-
chrono = { workspace = true }
15-
humantime = { workspace = true }
16-
log = { workspace = true }
17-
geo = { workspace = true }
18-
reqwest = { workspace = true }
19-
clap = { workspace = true }
20-
kdam = { workspace = true }

rust/bambam-omf/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@ keywords = [
1818
categories = ["command-line-utilities", "science", "science::geo"]
1919

2020
[dependencies]
21-
bamcensus-core = { workspace = true }
22-
bamcensus-acs = { workspace = true }
23-
bamcensus-lehd = { workspace = true }
24-
bamcensus = { workspace = true }
25-
routee-compass = { workspace = true }
26-
routee-compass-core = { workspace = true }
27-
routee-compass-powertrain = { workspace = true }
2821

2922
arrow = { workspace = true }
23+
bamcensus = { workspace = true }
24+
bamcensus-acs = { workspace = true }
25+
bamcensus-core = { workspace = true }
26+
bamcensus-lehd = { workspace = true }
3027
chrono = { workspace = true }
3128
clap = { workspace = true }
3229
config = { workspace = true }
@@ -41,17 +38,20 @@ itertools = { workspace = true }
4138
kdam = { workspace = true }
4239
log = { workspace = true }
4340
object_store = { workspace = true }
44-
parquet = { workspace = true }
4541
opening-hours-syntax = { workspace = true }
4642
ordered-float = { workspace = true }
43+
parquet = { workspace = true }
4744
rayon = { workspace = true }
4845
reqwest = { workspace = true }
46+
routee-compass = { workspace = true }
47+
routee-compass-core = { workspace = true }
48+
routee-compass-powertrain = { workspace = true }
4949
serde = { workspace = true }
50+
serde_arrow = { workspace = true }
5051
serde_bytes = { workspace = true }
5152
serde_json = { workspace = true }
52-
serde_arrow = { workspace = true }
5353
thiserror = { workspace = true }
5454
tokio = { workspace = true }
5555
uom = { workspace = true }
56-
wkt = { workspace = true }
5756
wkb = { workspace = true }
57+
wkt = { workspace = true }

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use crate::{
66
app::CliBoundingBox,
77
collection::{
88
filter::TravelModeFilter, ObjectStoreSource, OvertureMapsCollectionError,
9-
OvertureMapsCollectorConfig, ReleaseVersion, TransportationCollection,
9+
OvertureMapsCollectorConfig, ReleaseVersion, SegmentAccessRestrictionWhen,
10+
TransportationCollection,
1011
},
1112
graph::OmfGraphVectorized,
1213
util,
@@ -18,6 +19,20 @@ pub struct NetworkEdgeListConfiguration {
1819
pub filter: Vec<TravelModeFilter>,
1920
}
2021

22+
impl From<&NetworkEdgeListConfiguration> for SegmentAccessRestrictionWhen {
23+
fn from(value: &NetworkEdgeListConfiguration) -> Self {
24+
let user_modes_opt = value.filter.iter().find_map(|f| match f {
25+
TravelModeFilter::MatchesModeAccess { modes } => Some(modes.clone()),
26+
_ => None,
27+
});
28+
let mut result = SegmentAccessRestrictionWhen::default();
29+
if let Some(modes) = user_modes_opt {
30+
result.mode = Some(modes);
31+
}
32+
result
33+
}
34+
}
35+
2136
/// runs an OMF network import using the provided configuration.
2237
pub fn run(
2338
bbox: Option<&CliBoundingBox>,

rust/bambam-omf/src/collection/filter/travel_mode_filter.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ pub enum TravelModeFilter {
2424
MatchesClasses {
2525
classes: HashSet<SegmentClass>,
2626
behavior: MatchBehavior,
27-
ignore_unset: bool,
27+
allow_unset: bool,
2828
},
2929
/// filter a row based on a class with additional subclass(es). fails if not a match,
3030
/// and optionally, if 'class' or 'subclass' are unset.
3131
#[serde(rename = "class_with_subclasses")]
3232
MatchesClassesWithSubclasses {
3333
classes: HashMap<SegmentClass, Vec<SegmentSubclass>>,
3434
behavior: MatchBehavior,
35-
ignore_unset: bool,
35+
allow_unset: bool,
3636
},
3737

3838
/// filter a row based on the [SegmentMode].
@@ -145,35 +145,39 @@ impl TravelModeFilter {
145145
/// returns false if there is no match.
146146
pub fn matches_filter(&self, segment: &TransportationSegmentRecord) -> bool {
147147
match self {
148+
// subtype matching. default behavior is REJECT
148149
TravelModeFilter::MatchesSubtype { subtype } => segment
149150
.subtype
150151
.as_ref()
151152
.map(|s| s == subtype)
152153
.unwrap_or_default(),
153154

155+
// class matching. default behavior set by user (allow_unset).
154156
TravelModeFilter::MatchesClasses {
155157
classes,
156158
behavior,
157-
ignore_unset,
159+
allow_unset,
158160
} => segment
159161
.class
160162
.as_ref()
161163
.map(|c| behavior.apply(classes.contains(c)))
162-
.unwrap_or(*ignore_unset),
164+
.unwrap_or(*allow_unset),
163165

166+
// subclass matching. default behavior set by user (allow_unset).
164167
TravelModeFilter::MatchesClassesWithSubclasses {
165168
classes,
166169
behavior,
167-
ignore_unset,
170+
allow_unset,
168171
} => match (segment.class.as_ref(), segment.subclass.as_ref()) {
169172
(Some(cl), None) => behavior.apply(classes.contains_key(cl)),
170173
(Some(cl), Some(sc)) => match classes.get(cl) {
171-
None => *ignore_unset,
174+
None => *allow_unset,
172175
Some(subclasses) => behavior.apply(subclasses.contains(sc)),
173176
},
174-
_ => *ignore_unset,
177+
_ => *allow_unset,
175178
},
176179

180+
// mode matching. default behavior is ALLOW
177181
TravelModeFilter::MatchesModeAccess { modes } => {
178182
let restrictions = segment
179183
.access_restrictions

rust/bambam-omf/src/collection/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ mod collector;
22
mod collector_config;
33
mod error;
44
mod object_source;
5-
mod record;
65
mod taxonomy;
76
mod version;
87

98
pub mod constants;
109
pub mod filter;
10+
pub mod record;
1111

1212
pub use collector::OvertureMapsCollector;
1313
pub use collector_config::OvertureMapsCollectorConfig;
@@ -17,9 +17,10 @@ pub use filter::RowFilter;
1717
pub use filter::RowFilterConfig;
1818
pub use object_source::ObjectStoreSource;
1919
pub use record::{
20-
BuildingsRecord, OvertureRecord, OvertureRecordType, PlacesRecord, SegmentClass,
21-
SegmentFullType, SegmentSpeedLimit, SegmentSpeedUnit, SegmentSubclass, SegmentSubtype,
22-
TransportationCollection, TransportationConnectorRecord, TransportationSegmentRecord,
20+
BuildingsRecord, OvertureRecord, OvertureRecordType, PlacesRecord,
21+
SegmentAccessRestrictionWhen, SegmentClass, SegmentFullType, SegmentSpeedLimit,
22+
SegmentSpeedUnit, SegmentSubclass, SegmentSubtype, TransportationCollection,
23+
TransportationConnectorRecord, TransportationSegmentRecord,
2324
};
2425
pub use taxonomy::{TaxonomyModel, TaxonomyModelBuilder};
2526
pub use version::ReleaseVersion;

rust/bambam-omf/src/collection/record/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
33

4-
#[derive(Debug, Serialize, Deserialize, Clone)]
4+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
55
pub struct OvertureMapsBbox {
66
xmin: Option<f32>,
77
xmax: Option<f32>,
88
ymin: Option<f32>,
99
ymax: Option<f32>,
1010
}
1111

12-
#[derive(Debug, Serialize, Deserialize, Clone)]
12+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
1313
pub struct OvertureMapsSource {
1414
property: Option<String>,
1515
dataset: Option<String>,
@@ -18,14 +18,14 @@ pub struct OvertureMapsSource {
1818
confidence: Option<f64>,
1919
}
2020

21-
#[derive(Debug, Serialize, Deserialize, Clone)]
21+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
2222
pub struct OvertureMapsNames {
2323
primary: Option<String>,
2424
common: Option<HashMap<String, Option<String>>>,
2525
rules: Option<Vec<OvertureMapsNamesRule>>,
2626
}
2727

28-
#[derive(Debug, Serialize, Deserialize, Clone)]
28+
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
2929
struct OvertureMapsNamesRule {
3030
variant: Option<String>,
3131
language: Option<String>,

rust/bambam-omf/src/collection/record/geometry_wkb_codec.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use geo::{Geometry, MapCoords, TryConvert};
22
use geozero::{error::GeozeroError, wkb::Wkb, ToGeo};
33
use serde::{Deserialize, Deserializer};
4+
use serde_bytes;
45

5-
// Deserialize into an enum that can handle both Vec<u8> and String
6+
/// Deserialize into an enum that can handle both String and Vec<u8>, in
7+
/// that order.
68
#[derive(Deserialize)]
79
#[serde(untagged)]
810
enum BytesOrString {
9-
String(String), // The order here was important
10-
Bytes(serde_bytes::ByteBuf),
11+
String(String),
12+
#[serde(with = "serde_bytes")]
13+
Bytes(Vec<u8>),
1114
}
1215

1316
impl std::fmt::Display for BytesOrString {
@@ -28,7 +31,7 @@ where
2831

2932
data.map(|v| {
3033
let bytes = match &v {
31-
BytesOrString::Bytes(b) => b.clone().into_vec(),
34+
BytesOrString::Bytes(b) => b.clone(),
3235
BytesOrString::String(s) => hex::decode(s).map_err(|e| {
3336
serde::de::Error::custom(format!("failure converting hex wkb string to bytes: {e}"))
3437
})?,

rust/bambam-omf/src/collection/record/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ pub use record_type::OvertureRecordType;
1414
pub use transportation_collection::TransportationCollection;
1515
pub use transportation_connector::TransportationConnectorRecord;
1616
pub use transportation_segment::{
17-
SegmentAccessRestriction, SegmentAccessType, SegmentClass, SegmentFullType, SegmentHeading,
18-
SegmentMode, SegmentSpeedLimit, SegmentSpeedUnit, SegmentSubclass, SegmentSubtype,
17+
SegmentAccessRestriction, SegmentAccessRestrictionWhen, SegmentAccessType, SegmentClass,
18+
SegmentDestination, SegmentFullType, SegmentHeading, SegmentMode, SegmentRecognized,
19+
SegmentSpeedLimit, SegmentSpeedUnit, SegmentSubclass, SegmentSubtype, SegmentUsing,
1920
TransportationSegmentRecord,
2021
};
2122

2223
// Common structs and functions for many record types
23-
use common::OvertureMapsBbox;
24-
use common::OvertureMapsNames;
25-
use common::OvertureMapsSource;
24+
pub use common::OvertureMapsBbox;
25+
pub use common::OvertureMapsNames;
26+
pub use common::OvertureMapsSource;
2627
pub mod geometry_wkb_codec;

0 commit comments

Comments
 (0)