From 8fb4efa4b1a1ba977baf688bfd1205427cbd60d2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 5 Apr 2024 21:54:18 +0100 Subject: [PATCH] Try bundle classification based on the number of major roads --- osm2lanes/src/osm.rs | 49 ---------------------- osm2streets/src/block.rs | 43 +++++++++++++++---- web/src/street-explorer/RenderBlock.svelte | 1 + 3 files changed, 35 insertions(+), 58 deletions(-) diff --git a/osm2lanes/src/osm.rs b/osm2lanes/src/osm.rs index 771bd3f2..12afe8fe 100644 --- a/osm2lanes/src/osm.rs +++ b/osm2lanes/src/osm.rs @@ -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 - } -} diff --git a/osm2streets/src/block.rs b/osm2streets/src/block.rs index fb31f8bd..9de7f57f 100644 --- a/osm2streets/src/block.rs +++ b/osm2streets/src/block.rs @@ -311,6 +311,28 @@ fn classify_bundle( member_roads: &HashSet, member_intersections: &HashSet, ) -> 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) -> Result { diff --git a/web/src/street-explorer/RenderBlock.svelte b/web/src/street-explorer/RenderBlock.svelte index 080c0415..6e309b8a 100644 --- a/web/src/street-explorer/RenderBlock.svelte +++ b/web/src/street-explorer/RenderBlock.svelte @@ -33,6 +33,7 @@ LandUseBlock: "grey", RoadBundle: "green", IntersectionBundle: "orange", + Unknown: "blue", }; $: colors = $showingBundles ? bundleColors : blockColors;