From 93b36933f31b90058036b92ddf6f77f86500429f Mon Sep 17 00:00:00 2001 From: Matthias Marquardt Date: Thu, 24 May 2018 15:43:20 +0200 Subject: [PATCH 1/3] removing the code that is merging turn instructions --- .../ors/routing/RouteResultBuilder.java | 115 ++---------------- 1 file changed, 11 insertions(+), 104 deletions(-) diff --git a/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java b/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java index b475efc82e..c6f8453536 100644 --- a/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java +++ b/openrouteservice/src/main/java/heigit/ors/routing/RouteResultBuilder.java @@ -130,7 +130,7 @@ public RouteResult createRouteResult(List routes, RoutingRequest req // nInstructions -= 1; Instruction instr, prevInstr = null; - InstructionType instrType, prevInstrType = InstructionType.UNKNOWN; + InstructionType instrType = InstructionType.UNKNOWN; RouteSegment seg = new RouteSegment(path, units); if (includeDetourFactor) @@ -145,7 +145,6 @@ public RouteResult createRouteResult(List routes, RoutingRequest req seg.setDetourFactor((dist == 0) ? 0 : FormatUtility.roundToDecimals(path.getDistance()/dist, 2)); } - RouteStep prevStep = null; String instrText = ""; double stepDistance, stepDuration; @@ -217,49 +216,19 @@ else if (instrType == InstructionType.FINISH) } - // merge route steps with similar names - // example: http://localhost:8082/openrouteservice-4.0.0/routes?profile=driving-car&coordinates=8.690614,49.38365|8.7007,49.411699|8.7107,49.4516&prettify_instructions=true - if (prevStep != null && instrType == prevInstrType && canMergeInstructions(instr.getName(), prevInstr.getName())) - { - String mergedRoadName = mergeInstructions(instr.getName(), prevInstr.getName()); - - int[] wayPoints = prevStep.getWayPoints(); - wayPoints[1] = wayPoints[1] + instr.getPoints().size(); - - stepDuration = FormatUtility.roundToDecimals(instr.getTime()/1000.0, 1); + _nameAppendix = null; - prevStep.setDistance(FormatUtility.roundToDecimals(DistanceUnitUtil.convert(prevStep.getDistance() + stepDistance, DistanceUnit.Meters, units), unitDecimals)); - prevStep.setDuration(FormatUtility.roundToDecimals(prevStep.getDuration() + stepDuration, 1)); - prevStep.setName(mergedRoadName); - - if (_nameAppendix != null) - mergedRoadName += " ("+ _nameAppendix + ")"; - if (formatInstructions) - mergedRoadName = "" + mergedRoadName + ""; + step.setDistance(stepDistance); + step.setDuration(stepDuration); + step.setInstruction(instrText); + step.setName(instr.getName()); + step.setType(instrType.ordinal()); + step.setWayPoints(new int[] { startWayPointIndex, getWayPointEndIndex(startWayPointIndex, instrType, instr)}); - prevStep.setInstruction(instrTranslator.getContinue(instrType, mergedRoadName)); + if (request.getIncludeManeuvers()) + step.setManeuver(calcManeuver(instrType, prevSegPoints, segPoints, nextSegPoints)); - //if (request.getIncludeManeuvers()) - // prevStep.setManeuver(computeManeuver(prevSegPoints, segPoints)); - } - else - { - _nameAppendix = null; - - step.setDistance(stepDistance); - step.setDuration(stepDuration); - step.setInstruction(instrText); - step.setName(instr.getName()); - step.setType(instrType.ordinal()); - step.setWayPoints(new int[] { startWayPointIndex, getWayPointEndIndex(startWayPointIndex, instrType, instr)}); - - if (request.getIncludeManeuvers()) - step.setManeuver(calcManeuver(instrType, prevSegPoints, segPoints, nextSegPoints)); - - seg.addStep(step); - - prevStep = step; - } + seg.addStep(step); // step.setMessage(message); // add message and message type @@ -271,7 +240,6 @@ else if (instrType == InstructionType.FINISH) distanceActual += stepDistance; prevInstr = instr; - prevInstrType = instrType; prevSegPoints = segPoints; } @@ -449,67 +417,6 @@ private RouteStepManeuver calcManeuver(InstructionType instrType, PointList prev return maneuver; } - private boolean canMergeInstructions(String name, String prevName) - { - if (prevName == null) - return false; - - if (name.length() > prevName.length()) - { - int pos = name.indexOf(prevName); - if (pos >= 0 && !Helper.isEmpty(prevName)) - return true; - } - else - { - int pos = prevName.indexOf(name); - if (pos >= 0 && !Helper.isEmpty(name)) - return true; - } - - return false; - } - - private String mergeInstructionsOrdered(String name, String prevName) - { - int pos = name.indexOf(prevName); - if (pos >= 0) - { - pos = pos + prevName.length() + 1; - if (pos < name.length()) - { - String appendix = name.substring(pos, name.length()); - - if (appendix.length() > 1 && appendix.startsWith(",")) - appendix = appendix.substring(1); - - appendix = appendix.trim(); - - if (isValidAppendix(appendix)) - { - if (_nameAppendix != null) - _nameAppendix += ", "; - else - _nameAppendix = ""; - - _nameAppendix += appendix; - } - - return prevName; - } - } - - return name; - } - - private String mergeInstructions(String name, String prevName) - { - if (name.length() > prevName.length()) - return mergeInstructionsOrdered(name, prevName); - else - return mergeInstructionsOrdered(prevName, name); - } - private boolean isValidAppendix(String name) { if (name == null) From ddb1fd8c85cafacc363fb8eb43455fb6c835a7f4 Mon Sep 17 00:00:00 2001 From: marq24 Date: Wed, 30 May 2018 15:02:59 +0200 Subject: [PATCH 2/3] fixing broken TESTS --- .../src/test/java/heigit/ors/services/routing/ResultTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ResultTest.java b/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ResultTest.java index 182764bb72..7776d20c1d 100644 --- a/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ResultTest.java +++ b/openrouteservice-api-tests/src/test/java/heigit/ors/services/routing/ResultTest.java @@ -568,7 +568,7 @@ public void testSteps() { .body("routes[0].segments[0].containsKey('steps')", is(true)) .body("routes[0].segments[1].containsKey('steps')", is(true)) .body("routes[0].segments[0].steps.size()", is(55)) - .body("routes[0].segments[1].steps.size()", is(31)) + .body("routes[0].segments[1].steps.size()", is(33)) .statusCode(200); } @@ -588,7 +588,7 @@ public void testStepsDetails() { .body("routes[0].segments[0].containsKey('steps')", is(true)) .body("routes[0].segments[1].containsKey('steps')", is(true)) .body("routes[0].segments[0].steps.size()", is(55)) - .body("routes[0].segments[1].steps.size()", is(31)) + .body("routes[0].segments[1].steps.size()", is(33)) .body("routes[0].segments[0].steps[0].distance", is(511.4f)) .body("routes[0].segments[0].steps[0].duration", is(230.1f)) .body("routes[0].segments[0].steps[0].type", is(11)) From 73d81a5403aa950eb6233a2f0164591c8d670355 Mon Sep 17 00:00:00 2001 From: Matthias Marquardt Date: Tue, 5 Jun 2018 10:19:05 +0200 Subject: [PATCH 3/3] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 475ac21177..0ae0249c51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed problem with avoid polygons excluding ways that should have been accepted (Issue #95) +- Updated code to remove merging of instructions as this resulted in missing important turn instructions (Issue #177) ### Changed -