Skip to content

Commit

Permalink
Use most specific country code for which muv has a driving side
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHinshelwood authored and dabreegster committed Aug 25, 2024
1 parent ed21cad commit 98f4c92
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
23 changes: 11 additions & 12 deletions streets_reader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 14 additions & 14 deletions tests/src/frederiksted/geometry.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"country_code": "",
"country_code": "VI",
"features": [
{
"geometry": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tests/src/fremantle_placement/geometry.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"country_code": "",
"country_code": "AU",
"features": [
{
"geometry": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 98f4c92

Please sign in to comment.