From 751e569208d5047aaf1b664628e815e4abfd2040 Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Wed, 19 Nov 2014 12:47:43 -0500 Subject: [PATCH 1/3] Refactor countLanes() so that it gets the right number of lanes by itself (similar to getTurnLanesString()) --- .../osmand/router/RouteResultPreparation.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 2fd6711a36..908b200809 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -463,10 +463,7 @@ public class RouteResultPreparation { } private void assignLanesInfo(RouteSegmentResult prevSegm, TurnType t, boolean leftSide) { - int lanes = prevSegm.getObject().getLanes(); - if (prevSegm.getObject().getOneway() == 0) { - lanes = countLanes(prevSegm, lanes); - } + int lanes = countLanes(prevSegm); if (lanes <= 0) { return; } @@ -574,10 +571,7 @@ public class RouteResultPreparation { if (rsSpeakPriority != MAX_SPEAK_PRIORITY || speakPriority == MAX_SPEAK_PRIORITY) { if ((ex < TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex >= 0) { kl = true; - int lns = attached.getObject().getLanes(); - if(attached.getObject().getOneway() == 0) { - lns = countLanes(attached, lns); - } + int lns = countLanes(attached); if (lns <= 0) { right += 1; } else { @@ -586,10 +580,7 @@ public class RouteResultPreparation { speak = speak || rsSpeakPriority <= speakPriority; } else if ((ex > -TURN_DEGREE_MIN || mpi < TURN_DEGREE_MIN) && ex <= 0) { kr = true; - int lns = attached.getObject().getLanes(); - if(attached.getObject().getOneway() == 0) { - lns = countLanes(attached, lns); - } + int lns = countLanes(attached); if (lns <= 0) { left += 1; } else { @@ -605,11 +596,8 @@ public class RouteResultPreparation { } else if(kl && right == 0) { right = 1; } - int current = currentSegm.getObject().getLanes(); + int current = countLanes(currentSegm); // attachedRoutes covers all allowed outbound routes at that point except currentSegm. - if (currentSegm.getObject().getOneway() == 0) { - current = countLanes(currentSegm, current); - } if (current <= 0) { current = 1; } @@ -647,17 +635,23 @@ public class RouteResultPreparation { return t; } - protected int countLanes(RouteSegmentResult attached, int lns) { - try { - if (attached.isForwardDirection() && attached.getObject().getValue("lanes:forward") != null) { - return Integer.parseInt(attached.getObject().getValue("lanes:forward")); - } else if (!attached.isForwardDirection() && attached.getObject().getValue("lanes:backward") != null) { - return Integer.parseInt(attached.getObject().getValue("lanes:backward")); + protected int countLanes(RouteSegmentResult attached) { + if (attached.getObject().getOneway() == 0) { + try { + if (attached.isForwardDirection() && attached.getObject().getValue("lanes:forward") != null) { + return Integer.parseInt(attached.getObject().getValue("lanes:forward")); + } else if (!attached.isForwardDirection() && attached.getObject().getValue("lanes:backward") != null) { + return Integer.parseInt(attached.getObject().getValue("lanes:backward")); + } else { + return -1; + } + } catch (NumberFormatException e) { + e.printStackTrace(); + return -1; } - } catch (NumberFormatException e) { - e.printStackTrace(); + } else { + return attached.getObject().getLanes(); } - return (lns + 1) / 2; } protected String getTurnLanesString(RouteSegmentResult segment) { @@ -673,7 +667,7 @@ public class RouteResultPreparation { } private TurnType attachTurnLanesData(boolean leftSide, RouteSegmentResult prevSegm, TurnType t) { - int lanes = prevSegm.getObject().getLanes(); + int lanes = countLanes(prevSegm); String turnLanes = getTurnLanesString(prevSegm); if (turnLanes == null) { From 72f8c1e1f4420903e3332f8d510f85bdaafdd94c Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Wed, 19 Nov 2014 15:17:43 -0500 Subject: [PATCH 2/3] Remove main lanes restriction --- .../src/net/osmand/router/RouteResultPreparation.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 908b200809..1b141af83e 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -675,13 +675,9 @@ public class RouteResultPreparation { } String[] splitLaneOptions = turnLanes.split("\\|", -1); - if (splitLaneOptions.length != lanes) { - // Error in data or missing data - return t; - } if (t.getLanes().length != lanes) { - // The turn:lanes don't easily match up to the target road. + // The lanes from prevSegm don't easily match up to the target roads. List sourceLanes = new ArrayList(); int outgoingLanesIndex = 0; From fcee2c66422c10066a466b2aef3d1e65d8875cd2 Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Fri, 21 Nov 2014 11:31:18 -0500 Subject: [PATCH 3/3] Log inconsistencies in lanes and turn:lanes values, and try to adjust lanes array to continue processing. --- .../osmand/router/RouteResultPreparation.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 1b141af83e..3f4f979d1a 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -676,14 +676,41 @@ public class RouteResultPreparation { String[] splitLaneOptions = turnLanes.split("\\|", -1); + if (splitLaneOptions.length != lanes) { + log.warn("Number of lanes in lanes key (" + lanes + ") does not match number of lanes from turn:lanes key (" + splitLaneOptions.length + "). Errors may occur."); + + int leftLanes = 0; + int rightLanes = 0; + boolean processingLeft = true; + for (int i = 0; i < t.getLanes().length; i++) { + if (t.getLanes()[i] == 0) { + if (processingLeft) { + leftLanes++; + } else { + rightLanes++; + } + } else { + processingLeft = false; + } + } + + int[] adjustedLanes = new int[lanes + leftLanes + rightLanes]; + + for (int i = leftLanes; i < leftLanes + lanes; i++) { + adjustedLanes[i] = 1; + } + + t.setLanes(adjustedLanes); + } + if (t.getLanes().length != lanes) { - // The lanes from prevSegm don't easily match up to the target roads. + // The lanes from prevSegm don't easily match up to the target roads (it's not one-to-one). List sourceLanes = new ArrayList(); int outgoingLanesIndex = 0; int sourceLanesIndex = 0; - while (outgoingLanesIndex < t.getLanes().length && sourceLanesIndex < lanes) { + while (outgoingLanesIndex < t.getLanes().length && sourceLanesIndex < splitLaneOptions.length) { if (splitLaneOptions[sourceLanesIndex].contains(";")) { // Two or more allowed turns for this lane int options = countOccurrences(splitLaneOptions[sourceLanesIndex], ';');