public void createRteptBlock(StringBuilder output, Instruction instruction, Instruction nextI, DecimalFormat decimalFormat) { output.append("\n<rtept lat=\"").append(decimalFormat.format(instruction.getFirstLat())). append("\" lon=\"").append(decimalFormat.format(instruction.getFirstLon())).append("\">"); if (!instruction.getName().isEmpty()) output.append("<desc>").append(simpleXMLEscape(instruction.getTurnDescription(tr))).append("</desc>"); output.append("<extensions>"); output.append("<gh:distance>").append(Helper.round(instruction.getDistance(), 1)).append("</gh:distance>"); output.append("<gh:time>").append(instruction.getTime()).append("</gh:time>"); String direction = instruction.calcDirection(nextI); if (!direction.isEmpty()) output.append("<gh:direction>").append(direction).append("</gh:direction>"); double azimuth = instruction.calcAzimuth(nextI); if (!Double.isNaN(azimuth)) output.append("<gh:azimuth>").append(Helper.round2(azimuth)).append("</gh:azimuth>"); if (instruction instanceof RoundaboutInstruction) { RoundaboutInstruction ri = (RoundaboutInstruction) instruction; output.append("<gh:exit_number>").append(ri.getExitNumber()).append("</gh:exit_number>"); } output.append("<gh:sign>").append(instruction.getSign()).append("</gh:sign>"); output.append("</extensions>"); output.append("</rtept>"); }
public List<Map<String, Object>> createJson() { List<Map<String, Object>> instrList = new ArrayList<>(instructions.size()); int pointsIndex = 0; int counter = 0; for (Instruction instruction : instructions) { Map<String, Object> instrJson = new HashMap<>(); instrList.add(instrJson); InstructionAnnotation ia = instruction.getAnnotation(); String text = instruction.getTurnDescription(tr); if (Helper.isEmpty(text)) text = ia.getMessage(); instrJson.put("text", Helper.firstBig(text)); if (!ia.isEmpty()) { instrJson.put("annotation_text", ia.getMessage()); instrJson.put("annotation_importance", ia.getImportance()); } instrJson.put("street_name", instruction.getName()); instrJson.put("time", instruction.getTime()); instrJson.put("distance", Helper.round(instruction.getDistance(), 3)); instrJson.put("sign", instruction.getSign()); instrJson.putAll(instruction.getExtraInfoJSON()); int tmpIndex = pointsIndex + instruction.getLength(); instrJson.put("interval", Arrays.asList(pointsIndex, tmpIndex)); pointsIndex = tmpIndex; counter++; } return instrList; }
if (!Double.isNaN(prevInstructionPrevOrientation) && prevInstruction.getDistance() < MAX_U_TURN_DISTANCE && (sign < 0) == (prevInstruction.getSign() < 0) && (Math.abs(sign) == Instruction.TURN_SLIGHT_RIGHT || Math.abs(sign) == Instruction.TURN_RIGHT || Math.abs(sign) == Instruction.TURN_SHARP_RIGHT) && (Math.abs(prevInstruction.getSign()) == Instruction.TURN_SLIGHT_RIGHT || Math.abs(prevInstruction.getSign()) == Instruction.TURN_RIGHT || Math.abs(prevInstruction.getSign()) == Instruction.TURN_SHARP_RIGHT) && edge.isForward(encoder) != edge.isBackward(encoder) && InstructionsHelper.isNameSimilar(prevInstructionName, name)) {
@Test public void testCalcInstructionsForTurn() { // The street turns left, but there is not turn Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(11, 13); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain start, turn, and finish instruction assertEquals(3, wayList.size()); // Assert turn right assertEquals(2, wayList.get(1).getSign()); }
@Test public void testCalcInstructionsForSlightTurnWithOtherSlightTurn() { // Test for a fork with two sligh turns. Since there are two sligh turns, show the turn instruction Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(12, 16); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // Contain start, turn, and finish instruction assertEquals(3, wayList.size()); // Assert turn right assertEquals(7, wayList.get(1).getSign()); }
assertEquals(1604120, gpxList.get(gpxList.size() - 1).getTime()); assertEquals(Instruction.CONTINUE_ON_STREET, wayList.get(0).getSign()); assertEquals(15, wayList.get(0).getFirstLat(), 1e-3); assertEquals(10, wayList.get(0).getFirstLon(), 1e-3); assertEquals(Instruction.TURN_LEFT, wayList.get(1).getSign()); assertEquals(15.1, wayList.get(1).getFirstLat(), 1e-3); assertEquals(10, wayList.get(1).getFirstLon(), 1e-3); assertEquals(Instruction.TURN_RIGHT, wayList.get(2).getSign()); assertEquals(15.1, wayList.get(2).getFirstLat(), 1e-3); assertEquals(9.9, wayList.get(2).getFirstLon(), 1e-3);
int indi = getSign(); if (indi == Instruction.CONTINUE_ON_STREET) { str = Helper.isEmpty(streetName) ? tr.tr("continue") : tr.tr("continue_onto", streetName);
assertEquals(Instruction.CONTINUE_ON_STREET, nextInstr0.getSign()); assertEquals(Instruction.TURN_RIGHT, nextInstr1.getSign()); assertEquals(Instruction.TURN_LEFT, nextInstr2.getSign()); assertEquals(Instruction.TURN_SHARP_LEFT, nextInstr3.getSign()); assertEquals(Instruction.FINISH, nextInstr4.getSign());
@Test public void testCalcInstructionContinueLeavingStreet() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // When leaving the current street via a Continue, we should show it // 3 // \ // 4 - 2 -- 1 na.setNode(1, 48.982618, 13.122021); na.setNode(2, 48.982565, 13.121597); na.setNode(3, 48.982611, 13.121012); na.setNode(4, 48.982565, 13.121002); g.edge(1, 2, 5, true).setName("Regener Weg"); g.edge(2, 4, 5, true); g.edge(2, 3, 5, true).setName("Regener Weg"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 4); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(-7, wayList.get(1).getSign()); }
@Test public void testCalcInstructionSlightTurn() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Real Situation: point=48.411927%2C15.599197&point=48.412094%2C15.598816 // When reaching this Crossing, you cannot know if you should turn left or right // Google Maps and Bing show a turn, OSRM does not // 1 ---2--- 3 // \ // 4 na.setNode(1, 48.412094, 15.598816); na.setNode(2, 48.412055, 15.599068); na.setNode(3, 48.412034, 15.599411); na.setNode(4, 48.411927, 15.599197); g.edge(1, 2, 5, true).setName("Stöhrgasse"); g.edge(2, 3, 5, true); g.edge(2, 4, 5, true).setName("Stöhrgasse"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(4, 1); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(-1, wayList.get(1).getSign()); }
@Test public void testCalcInstructionsOntoOneway() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Actual example: point=-33.824566%2C151.187834&point=-33.82441%2C151.188231 // 1 -2 -3 is a oneway // 1 ->- 2 ->- 3 // | // 4 na.setNode(1, -33.824245, 151.187866); na.setNode(2, -33.824335, 151.188017); na.setNode(3, -33.824415, 151.188177); na.setNode(4, -33.824437, 151.187925); g.edge(1, 2, 5, false).setName("Pacific Highway"); g.edge(2, 3, 5, false).setName("Pacific Highway"); g.edge(4, 2, 5, true).setName("Greenwich Road"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(4, 3); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(2, wayList.get(1).getSign()); }
@Test public void testCalcInstructionsForSlightTurnOntoDifferentStreet() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Actual example: point=48.76445%2C8.679054&point=48.764152%2C8.678722 // 1 // / // 2 - 3 - 4 // na.setNode(1, 48.76423, 8.679103); na.setNode(2, 48.76417, 8.678647); na.setNode(3, 48.764149, 8.678926); na.setNode(4, 48.764085, 8.679183); g.edge(1, 3, 5, true).setName("Talstraße, K 4313"); g.edge(2, 3, 5, true).setName("Calmbacher Straße, K 4312"); g.edge(3, 4, 5, true).setName("Calmbacher Straße, K 4312"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 2); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(Instruction.TURN_SLIGHT_RIGHT, wayList.get(1).getSign()); }
@Test public void testCalcInstructionForForkWithSameName() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Actual example: point=48.982618%2C13.122021&point=48.982336%2C13.121002 // 1-2 & 2-4 have the same Street name, but other from that, it would be hard to see the difference // We have to enforce a turn instruction here // 3 // \ // 2 -- 1 // / // 4 na.setNode(1, 48.982618, 13.122021); na.setNode(2, 48.982565, 13.121597); na.setNode(3, 48.982611, 13.121012); na.setNode(4, 48.982336, 13.121002); g.edge(1, 2, 5, true).setName("Regener Weg"); g.edge(2, 4, 5, true).setName("Regener Weg"); g.edge(2, 3, 5, true); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 4); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(-7, wayList.get(1).getSign()); }
@Test public void testCalcInstructionsMotowayJunction() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Actual example: point=48.70672%2C9.164266&point=48.706805%2C9.162995 // A typical motorway junction, when following 1-2-3, there should be a keep right at 2 // -- 4 // / // 1 -- 2 -- 3 na.setNode(1, 48.70672, 9.164266); na.setNode(2, 48.706741, 9.163719); na.setNode(3, 48.706805, 9.162995); na.setNode(4, 48.706705, 9.16329); g.edge(1, 2, 5, false).setName("A 8"); g.edge(2, 3, 5, false).setName("A 8"); g.edge(2, 4, 5, false).setName("A 8"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 3); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); // TODO this should be a keep_right assertEquals(0, wayList.get(1).getSign()); }
@Test public void testUTurnRight() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Real Situation: point=-33.885758,151.181472&point=-33.885692,151.181445 // 7 // | // 4----5----6 // | // 3----2----1 na.setNode(1, -33.885758, 151.181472); na.setNode(2, -33.885852, 151.180968); na.setNode(3, -33.885968, 151.180501); na.setNode(4, -33.885883, 151.180442); na.setNode(5, -33.885772, 151.180941); na.setNode(6, -33.885692, 151.181445); na.setNode(7, -33.885692, 151.181445); g.edge(1, 2, 5, false).setName("Parramatta Road"); g.edge(2, 3, 5, false).setName("Parramatta Road"); g.edge(4, 5, 5, false).setName("Parramatta Road"); g.edge(5, 6, 5, false).setName("Parramatta Road"); g.edge(2, 5, 5, true).setName("Larkin Street"); g.edge(5, 7, 5, true).setName("Larkin Street"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 6); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(Instruction.U_TURN_RIGHT, wayList.get(1).getSign()); }
@Test public void testUTurnLeft() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Real Situation: point=48.402116%2C9.994367&point=48.402198%2C9.99507 // 7 // | // 4----5----6 // | // 1----2----3 na.setNode(1, 48.402116, 9.994367); na.setNode(2, 48.402198, 9.99507); na.setNode(3, 48.402344, 9.996266); na.setNode(4, 48.402191, 9.994351); na.setNode(5, 48.402298, 9.995053); na.setNode(6, 48.402422, 9.996067); na.setNode(7, 48.402604, 9.994962); g.edge(1, 2, 5, false).setName("Olgastraße"); g.edge(2, 3, 5, false).setName("Olgastraße"); g.edge(6, 5, 5, false).setName("Olgastraße"); g.edge(5, 4, 5, false).setName("Olgastraße"); g.edge(2, 5, 5, true).setName("Neithardtstraße"); g.edge(5, 7, 5, true).setName("Neithardtstraße"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(1, 4); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); assertEquals(3, wayList.size()); assertEquals(Instruction.U_TURN_LEFT, wayList.get(1).getSign()); }
public void createRteptBlock(StringBuilder output, Instruction instruction, Instruction nextI) { output.append("\n<rtept lat=\"").append(Helper.round6(instruction.getFirstLat())). append("\" lon=\"").append(Helper.round6(instruction.getFirstLon())).append("\">"); if (!instruction.getName().isEmpty()) output.append("<desc>").append(simpleXMLEscape(instruction.getTurnDescription(tr))).append("</desc>"); output.append("<extensions>"); output.append("<gh:distance>").append(Helper.round(instruction.getDistance(), 1)).append("</gh:distance>"); output.append("<gh:time>").append(instruction.getTime()).append("</gh:time>"); String direction = instruction.calcDirection(nextI); if (!direction.isEmpty()) output.append("<gh:direction>").append(direction).append("</gh:direction>"); double azimuth = instruction.calcAzimuth(nextI); if (!Double.isNaN(azimuth)) output.append("<gh:azimuth>").append(Helper.round2(azimuth)).append("</gh:azimuth>"); output.append("<gh:sign>").append(instruction.getSign()).append("</gh:sign>"); output.append("</extensions>"); output.append("</rtept>"); }
public void createRteptBlock( StringBuilder output, Instruction instruction, Instruction nextI ) { output.append("\n<rtept lat=\"").append(Helper.round6(instruction.getFirstLat())). append("\" lon=\"").append(Helper.round6(instruction.getFirstLon())).append("\">"); if (!instruction.getName().isEmpty()) output.append("<desc>").append(simpleXMLEscape(instruction.getTurnDescription(tr))).append("</desc>"); output.append("<extensions>"); output.append("<gh:distance>").append(Helper.round(instruction.getDistance(), 1)).append("</gh:distance>"); output.append("<gh:time>").append(instruction.getTime()).append("</gh:time>"); String direction = instruction.calcDirection(nextI); if (!direction.isEmpty()) output.append("<gh:direction>").append(direction).append("</gh:direction>"); double azimuth = instruction.calcAzimuth(nextI); if (!Double.isNaN(azimuth)) output.append("<gh:azimuth>").append(Helper.round2(azimuth)).append("</gh:azimuth>"); output.append("<gh:sign>").append(instruction.getSign()).append("</gh:sign>"); output.append("</extensions>"); output.append("</rtept>"); }