From 98f4c92ca6e205613d45d0088e9ebb74e386d713 Mon Sep 17 00:00:00 2001 From: James Hinshelwood Date: Sun, 25 Aug 2024 21:48:08 +0100 Subject: [PATCH] Use most specific country code for which `muv` has a driving side --- streets_reader/src/lib.rs | 23 ++++++++--------- tests/src/frederiksted/geometry.json | 28 ++++++++++----------- tests/src/fremantle_placement/geometry.json | 6 ++--- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/streets_reader/src/lib.rs b/streets_reader/src/lib.rs index 7c3ebd6d..6b93105b 100644 --- a/streets_reader/src/lib.rs +++ b/streets_reader/src/lib.rs @@ -59,19 +59,18 @@ pub fn detect_country_code(streets: &mut StreetNetwork) { // Obtain the possible list of country codes, ordered by their size ascending. let codes = geocoder.ids(country_boundaries::LatLon::new(pt.y(), pt.x()).unwrap()); - // Use the first code, since it is most specific. - if let Some(code) = codes.first() { - streets.config.country_code = code.to_string(); - let driving_side = match driving_side(&code) { - Some(muv_osm::lanes::Side::Left) => DrivingSide::Left, - Some(muv_osm::lanes::Side::Right) => DrivingSide::Right, - // Default to driving on the right. - None => DrivingSide::Right, - }; - streets.config.driving_side = driving_side; - } else { + + // Use the most specific country code for which we know a driving side. + let Some((code, side)) = codes.into_iter().find_map(|code| driving_side(code).map(|s| (code, s))) else { error!("detect_country_code failed -- {:?} didn't match to any country. Driving side may be wrong!", pt); - } + return; + }; + + streets.config.country_code = code.to_string(); + streets.config.driving_side = match side { + muv_osm::lanes::Side::Left => DrivingSide::Left, + muv_osm::lanes::Side::Right => DrivingSide::Right, + }; } fn extract_osm( diff --git a/tests/src/frederiksted/geometry.json b/tests/src/frederiksted/geometry.json index c10a4971..1c0f0169 100644 --- a/tests/src/frederiksted/geometry.json +++ b/tests/src/frederiksted/geometry.json @@ -1,5 +1,5 @@ { - "country_code": "", + "country_code": "VI", "features": [ { "geometry": { @@ -4815,7 +4815,7 @@ "control": "Signed", "crossing": null, "id": 3, - "intersection_kind": "Fork", + "intersection_kind": "Intersection", "movements": [ "Road #13 -> Road #1", "Road #0 -> Road #1", @@ -4860,7 +4860,7 @@ "control": "Signed", "crossing": null, "id": 4, - "intersection_kind": "Intersection", + "intersection_kind": "Connection", "movements": [ "Road #57 -> Road #18", "Road #18 -> Road #57" @@ -4908,7 +4908,7 @@ "control": "Signed", "crossing": null, "id": 5, - "intersection_kind": "Fork", + "intersection_kind": "Intersection", "movements": [ "Road #19 -> Road #2", "Road #1 -> Road #2", @@ -5009,7 +5009,7 @@ "control": "Signed", "crossing": null, "id": 7, - "intersection_kind": "Fork", + "intersection_kind": "Intersection", "movements": [ "Road #24 -> Road #3", "Road #2 -> Road #3", @@ -5564,7 +5564,7 @@ "control": "Signed", "crossing": null, "id": 16, - "intersection_kind": "Intersection", + "intersection_kind": "Connection", "movements": [ "Road #68 -> Road #35", "Road #35 -> Road #68" @@ -7724,7 +7724,7 @@ "control": "Signed", "crossing": null, "id": 54, - "intersection_kind": "Intersection", + "intersection_kind": "Connection", "movements": [ "Road #92 -> Road #91", "Road #91 -> Road #92" @@ -7858,7 +7858,7 @@ "control": "Signed", "crossing": null, "id": 57, - "intersection_kind": "Intersection", + "intersection_kind": "Fork", "movements": [ "Road #5 -> Road #6", "Road #5 -> Road #87", @@ -7907,7 +7907,7 @@ "control": "Signed", "crossing": null, "id": 58, - "intersection_kind": "Intersection", + "intersection_kind": "Connection", "movements": [ "Road #87 -> Road #88", "Road #88 -> Road #87" @@ -7996,7 +7996,7 @@ "control": "Signed", "crossing": null, "id": 60, - "intersection_kind": "Intersection", + "intersection_kind": "Fork", "movements": [ "Road #3 -> Road #4", "Road #3 -> Road #90", @@ -8045,7 +8045,7 @@ "control": "Signed", "crossing": null, "id": 61, - "intersection_kind": "Intersection", + "intersection_kind": "Connection", "movements": [ "Road #90 -> Road #91", "Road #91 -> Road #90" @@ -8227,7 +8227,7 @@ "control": "Signed", "crossing": null, "id": 65, - "intersection_kind": "Intersection", + "intersection_kind": "Connection", "movements": [ "Road #42 -> Road #41", "Road #41 -> Road #42" @@ -8335,7 +8335,7 @@ "control": "Signed", "crossing": null, "id": 67, - "intersection_kind": "Fork", + "intersection_kind": "Intersection", "movements": [ "Road #96 -> Road #7", "Road #6 -> Road #7", @@ -8384,7 +8384,7 @@ "control": "Signed", "crossing": null, "id": 68, - "intersection_kind": "Fork", + "intersection_kind": "Intersection", "movements": [ "Road #97 -> Road #5", "Road #4 -> Road #5", diff --git a/tests/src/fremantle_placement/geometry.json b/tests/src/fremantle_placement/geometry.json index c466a275..2f1416c5 100644 --- a/tests/src/fremantle_placement/geometry.json +++ b/tests/src/fremantle_placement/geometry.json @@ -1,5 +1,5 @@ { - "country_code": "", + "country_code": "AU", "features": [ { "geometry": { @@ -3194,7 +3194,7 @@ "control": "Signed", "crossing": null, "id": 8, - "intersection_kind": "Intersection", + "intersection_kind": "Fork", "movements": [ "Road #12 -> Road #5", "Road #12 -> Road #13", @@ -4287,7 +4287,7 @@ "control": "Signed", "crossing": null, "id": 32, - "intersection_kind": "Intersection", + "intersection_kind": "Fork", "movements": [ "Road #31 -> Road #63", "Road #31 -> Road #32",