From 39880e559b24eeff7d55d79a05a1d8f6888084c6 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 20 Jan 2019 22:07:07 +0000 Subject: [PATCH] Add direction of travel to turn restriction errors --- data/core.yaml | 11 +++++++++- dist/locales/en.json | 12 ++++++++++- modules/services/improveOSM.js | 38 +++++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index eee91225b..a19cc3300 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -668,6 +668,15 @@ en: parking: parking areas road: roads both: roads and parking + directions: + east: east + north: north + northeast: northeast + northwest: northwest + south: south + southeast: southeast + southwest: southwest + west: west error_types: ow: title: Missing One-way @@ -677,7 +686,7 @@ en: description: '{num_trips} recorded trips in this area suggest there may be unmapped {geometry_type} here.' tr: title: Missing Turn Restriction - description: '{num_passed} of {num_trips} recorded trips make a turn from {from_way} to {to_way}. There may be a missing "{turn_restriction}" restriction.' + description: '{num_passed} of {num_trips} recorded trips (travelling {travel_direction}) make a turn from {from_way} to {to_way}. There may be a missing "{turn_restriction}" restriction.' keepRight: title: KeepRight Error detail_title: Error diff --git a/dist/locales/en.json b/dist/locales/en.json index b904101d1..7f674fd0e 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -811,6 +811,16 @@ "road": "roads", "both": "roads and parking" }, + "directions": { + "east": "east", + "north": "north", + "northeast": "northeast", + "northwest": "northwest", + "south": "south", + "southeast": "southeast", + "southwest": "southwest", + "west": "west" + }, "error_types": { "ow": { "title": "Missing One-way", @@ -822,7 +832,7 @@ }, "tr": { "title": "Missing Turn Restriction", - "description": "{num_passed} of {num_trips} recorded trips make a turn from {from_way} to {to_way}. There may be a missing \"{turn_restriction}\" restriction." + "description": "{num_passed} of {num_trips} recorded trips (travelling {travel_direction}) make a turn from {from_way} to {to_way}. There may be a missing \"{turn_restriction}\" restriction." } } }, diff --git a/modules/services/improveOSM.js b/modules/services/improveOSM.js index e36734ff3..a203dace1 100644 --- a/modules/services/improveOSM.js +++ b/modules/services/improveOSM.js @@ -83,7 +83,34 @@ function pointAverage(points) { x /= points.length; y /= points.length; - return [x, y] + return [x, y]; +} + +function relativeBearing(p1, p2) { + var angle = Math.atan2(p2.lon - p1.lon, p2.lat - p1.lat); + if (angle < 0) { + angle += 2 * Math.PI; + } + + // Return degrees + return angle * 180 / Math.PI; +} + +// Assuming range [0,360) +function cardinalDirection(bearing) { + var dir = 45 * Math.round(bearing / 45); + var compass = { + 0: 'north', + 45: 'northeast', + 90: 'east', + 135: 'southeast', + 180: 'south', + 225: 'southwest', + 270: 'west', + 315: 'northwest' + }; + + return t('QA.improveOSM.directions.' + compass[dir]); } export default { @@ -214,6 +241,11 @@ export default { var via_node = ids[3]; var to_way = ids[2].split(':')[1]; + var p1 = feature.segments[0].points[0]; + var p2 = feature.segments[0].points[1]; + + var dir_of_travel = cardinalDirection(relativeBearing(p1, p2)); + var d = new impOsmError({ loc: [loc.lon, loc.lat], comments: null, @@ -224,13 +256,13 @@ export default { }); // Variables used in the description - //TODO: Add direction of travel d.replacements = { num_passed: feature.numberOfPasses, num_trips: feature.segments[0].numberOfTrips, turn_restriction: feature.turnType.toLowerCase(), from_way: linkEntity('w' + from_way), - to_way: linkEntity('w' + to_way) + to_way: linkEntity('w' + to_way), + travel_direction: dir_of_travel }; _erCache.data[d.id] = d;