Skip to content

Commit

Permalink
Try bundle classification based on the number of major roads
Browse files Browse the repository at this point in the history
dabreegster committed Apr 5, 2024
1 parent 759c515 commit 8fb4efa
Showing 3 changed files with 35 additions and 58 deletions.
49 changes: 0 additions & 49 deletions osm2lanes/src/osm.rs
Original file line number Diff line number Diff line change
@@ -4,52 +4,3 @@ pub use osm_reader::{NodeID, OsmID, RelationID, WayID};

// This is a commonly used key in the codebase, so worthy of a bit of typo-prevention
pub const HIGHWAY: &str = "highway";

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug)]
pub enum RoadRank {
Local,
Arterial,
Highway,
}

impl RoadRank {
pub fn from_highway(hwy: &str) -> RoadRank {
match hwy {
"motorway" | "motorway_link" => RoadRank::Highway,
"trunk" | "trunk_link" => RoadRank::Highway,
"primary" | "primary_link" => RoadRank::Arterial,
"secondary" | "secondary_link" => RoadRank::Arterial,
"tertiary" | "tertiary_link" => RoadRank::Arterial,
_ => RoadRank::Local,
}
}

/// Larger number means a bigger road, according to https://wiki.openstreetmap.org/wiki/Key:highway
pub fn detailed_from_highway(hwy: &str) -> usize {
for (idx, x) in vec![
"motorway",
"motorway_link",
"trunk",
"trunk_link",
"primary",
"primary_link",
"secondary",
"secondary_link",
"tertiary",
"tertiary_link",
"unclassified",
"residential",
"cycleway",
"track",
]
.into_iter()
.enumerate()
{
if hwy == x {
return 100 - idx;
}
}
// Everything else gets lowest priority
0
}
}
43 changes: 34 additions & 9 deletions osm2streets/src/block.rs
Original file line number Diff line number Diff line change
@@ -311,6 +311,28 @@ fn classify_bundle(
member_roads: &HashSet<RoadID>,
member_intersections: &HashSet<IntersectionID>,
) -> BlockKind {
// See how many "major" named roads are inside
if true {
let mut major_road_names = HashSet::new();

for r in member_roads {
let road = &streets.roads[r];
if let Some(name) = road.name.clone() {
if road.highway_type != "service" {
major_road_names.insert(name);
}
}
}

return if major_road_names.len() == 0 {
BlockKind::LandUseBlock
} else if major_road_names.len() == 1 {
BlockKind::RoadBundle
} else {
BlockKind::IntersectionBundle
};
}

if member_intersections.is_empty() && member_roads.is_empty() {
return BlockKind::LandUseBlock;
}
@@ -335,16 +357,19 @@ fn classify_bundle(
}
}

// TODO Check member road names and ignore service roads?

// See how "square" the block polygon is. Even if it's not axis-aligned, this sometimes works
let bounds = polygon.get_bounds();
let ratio = bounds.width() / bounds.height();
if ratio > 0.5 && ratio < 2.0 {
return BlockKind::IntersectionBundle;
} else {
return BlockKind::RoadBundle;
// See how "square" the block polygon is.
// TODO Need to axis-align this first for it to have hope
if false {
let bounds = polygon.get_bounds();
let ratio = bounds.width() / bounds.height();
if ratio > 0.5 && ratio < 2.0 {
return BlockKind::IntersectionBundle;
} else {
return BlockKind::RoadBundle;
}
}

BlockKind::Unknown
}

fn serialize_features(features: Vec<Feature>) -> Result<String> {
1 change: 1 addition & 0 deletions web/src/street-explorer/RenderBlock.svelte
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
LandUseBlock: "grey",
RoadBundle: "green",
IntersectionBundle: "orange",
Unknown: "blue",
};
$: colors = $showingBundles ? bundleColors : blockColors;

0 comments on commit 8fb4efa

Please sign in to comment.