@Override public EdgeIteratorState setName(String name) { return edges.get(current).setName(name); }
public void applyWayTags(ReaderWay way, EdgeIteratorState edge) { // storing the road name does not yet depend on the flagEncoder so manage it directly if (enableInstructions) { // String wayInfo = carFlagEncoder.getWayInfo(way); // http://wiki.openstreetmap.org/wiki/Key:name String name = ""; if (!preferredLanguage.isEmpty()) name = fixWayName(way.getTag("name:" + preferredLanguage)); if (name.isEmpty()) name = fixWayName(way.getTag("name")); // http://wiki.openstreetmap.org/wiki/Key:ref String refName = fixWayName(way.getTag("ref")); if (!refName.isEmpty()) { if (name.isEmpty()) name = refName; else name += ", " + refName; } edge.setName(name); } for (AbstractFlagEncoder encoder : edgeEncoders) { encoder.applyWayTags(way, edge); } }
@Override public EdgeIteratorState detach(boolean reverse) { if (reverse) { reverseEdge.setFlags(getFlags()); reverseEdge.setName(getName()); reverseEdge.setDistance(getDistance()); return reverseEdge; } else { return this; } }
/** * @return to */ EdgeIteratorState copyProperties(CommonEdgeIterator from, EdgeIteratorState to) { to.setDistance(from.getDistance()). setName(from.getName()). setFlags(from.getDirectFlags()). setWayGeometry(from.fetchWayGeometry(0)); if (E_ADDITIONAL >= 0) to.setAdditionalField(from.getAdditionalField()); return to; }
boardEdge.setName(getRouteName(feed, trip)); setEdgeTypeAndClearDistance(boardEdge, GtfsStorage.EdgeType.BOARD); gtfsStorage.getStopSequences().put(boardEdge.getEdge(), stopSequence);
private void wireUpArrivalTimeline(int streetNode, Stop stop, NavigableMap<Integer, Integer> arrivalTimeline, int route_type, GtfsStorageI.PlatformDescriptor platformDescriptorIfStatic) { nodeAccess.setNode(i++, stop.stop_lat, stop.stop_lon); int stopExitNode = i - 1; nodeAccess.setAdditionalNodeField(stopExitNode, NodeType.STOP_EXIT_NODE.ordinal()); EdgeIteratorState exitEdge = graph.edge(stopExitNode, streetNode); exitEdge.setFlags(encoder.setAccess(exitEdge.getFlags(), true, false)); setEdgeTypeAndClearDistance(exitEdge, GtfsStorage.EdgeType.EXIT_PT); exitEdge.setFlags(encoder.setValidityId(exitEdge.getFlags(), route_type)); exitEdge.setName(stop.stop_name); if (platformDescriptorIfStatic != null) { gtfsStorage.getRoutes().put(exitEdge.getEdge(), platformDescriptorIfStatic); } wireUpAndConnectTimeline(stop, stopExitNode, arrivalTimeline, GtfsStorage.EdgeType.LEAVE_TIME_EXPANDED_NETWORK, GtfsStorage.EdgeType.WAIT_ARRIVAL); }
private void wireUpDepartureTimeline(int streetNode, Stop stop, NavigableMap<Integer, Integer> departureTimeline, int route_type, GtfsStorageI.PlatformDescriptor platformDescriptorIfStatic) { nodeAccess.setNode(i++, stop.stop_lat, stop.stop_lon); int stopEnterNode = i - 1; nodeAccess.setAdditionalNodeField(stopEnterNode, NodeType.STOP_ENTER_NODE.ordinal()); EdgeIteratorState entryEdge = graph.edge(streetNode, stopEnterNode); entryEdge.setFlags(encoder.setAccess(entryEdge.getFlags(), true, false)); setEdgeTypeAndClearDistance(entryEdge, GtfsStorage.EdgeType.ENTER_PT); entryEdge.setFlags(encoder.setValidityId(entryEdge.getFlags(), route_type)); entryEdge.setName(stop.stop_name); if (platformDescriptorIfStatic != null) { gtfsStorage.getRoutes().put(entryEdge.getEdge(), platformDescriptorIfStatic); } wireUpAndConnectTimeline(stop, stopEnterNode, departureTimeline, GtfsStorage.EdgeType.ENTER_TIME_EXPANDED_NETWORK, GtfsStorage.EdgeType.WAIT); }
@Test public void testNameIndex() { graph = createGHStorage(); EdgeIteratorState iter1 = graph.edge(0, 1, 10, true); iter1.setName("named street1"); EdgeIteratorState iter2 = graph.edge(0, 1, 10, true); iter2.setName("named street2"); assertEquals("named street1", graph.getEdgeIteratorState(iter1.getEdge(), iter1.getAdjNode()).getName()); assertEquals("named street2", graph.getEdgeIteratorState(iter2.getEdge(), iter2.getAdjNode()).getName()); }
@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 testCalcInstructionsEnterMotoway() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); // Actual example: point=48.630533%2C9.459416&point=48.630544%2C9.459829 // 1 -2 -3 is a motorway and tagged as oneway // 1 ->- 2 ->- 3 // / // 4 na.setNode(1, 48.630647, 9.459041); na.setNode(2, 48.630586, 9.459604); na.setNode(3, 48.630558, 9.459851); na.setNode(4, 48.63054, 9.459406); g.edge(1, 2, 5, false).setName("A 8"); g.edge(2, 3, 5, false).setName("A 8"); g.edge(4, 2, 5, false).setName("A 8"); Path p = new Dijkstra(g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED) .calcPath(4, 3); assertTrue(p.isFound()); InstructionList wayList = p.calcInstructions(tr); // no turn instruction for entering the highway assertEquals(2, wayList.size()); }
@Test public void testNoInstructionIfSameStreet() { Graph g = new GraphBuilder(carManager).create(); // 2 // \. 5 // \/ // 4 // / // 3 NodeAccess na = g.getNodeAccess(); na.setNode(2, 10.3, 10.15); na.setNode(3, 10.0, 10.05); na.setNode(4, 10.1, 10.10); na.setNode(5, 10.2, 10.15); g.edge(3, 4, 100, true).setName("street"); g.edge(4, 5, 100, true).setName("4-5"); EdgeIteratorState iter = g.edge(2, 4, 100, true); iter.setName("street"); PointList list = new PointList(); list.add(10.20, 10.05); iter.setWayGeometry(list); Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3); InstructionList wayList = p.calcInstructions(usTR); List<String> tmpList = pick("text", wayList.createJson()); assertEquals(Arrays.asList("Continue onto street", "Turn right onto street", "Arrive at destination"), tmpList); }
private Graph generatePathDetailsGraph() { final Graph g = new GraphBuilder(carManager).create(); final NodeAccess na = g.getNodeAccess(); na.setNode(1, 52.514, 13.348); na.setNode(2, 52.514, 13.349); na.setNode(3, 52.514, 13.350); na.setNode(4, 52.515, 13.349); na.setNode(5, 52.516, 13.3452); ReaderWay w = new ReaderWay(1); w.setTag("highway", "tertiary"); w.setTag("maxspeed", "50"); EdgeIteratorState tmpEdge; tmpEdge = g.edge(1, 2, 5, true).setName("1-2"); tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0)); tmpEdge = g.edge(4, 5, 5, true).setName("4-5"); tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0)); w.setTag("maxspeed", "100"); tmpEdge = g.edge(2, 3, 5, true).setName("2-3"); tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0)); w.setTag("maxspeed", "10"); tmpEdge = g.edge(3, 4, 10, true).setName("3-4"); tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0)); return g; }
@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 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 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 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 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 testCopyProperties() { graph = createGHStorage(); EdgeIteratorState edge = graph.edge(1, 3, 10, false).setName("testing").setWayGeometry(Helper.createPointList(1, 2)); EdgeIteratorState newEdge = graph.edge(1, 3, 10, false); edge.copyPropertiesTo(newEdge); assertEquals(edge.getName(), newEdge.getName()); assertEquals(edge.getDistance(), newEdge.getDistance(), 1e-7); assertEquals(edge.getFlags(), newEdge.getFlags()); assertEquals(edge.fetchWayGeometry(0), newEdge.fetchWayGeometry(0)); }
@Test public void testSave_and_fileFormat() throws IOException { graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), true).create(defaultSize); NodeAccess na = graph.getNodeAccess(); assertTrue(na.is3D()); na.setNode(0, 10, 10, 0); na.setNode(1, 11, 20, 1); na.setNode(2, 12, 12, 0.4); EdgeIteratorState iter2 = graph.edge(0, 1, 100, true); iter2.setWayGeometry(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0)); EdgeIteratorState iter1 = graph.edge(0, 2, 200, true); iter1.setWayGeometry(Helper.createPointList3D(3.5, 4.5, 0, 5, 6, 0)); graph.edge(9, 10, 200, true); graph.edge(9, 11, 200, true); graph.edge(1, 2, 120, false); iter1.setName("named street1"); iter2.setName("named street2"); checkGraph(graph); graph.flush(); graph.close(); graph = newGHStorage(new MMapDirectory(defaultGraphLoc), true); assertTrue(graph.loadExisting()); assertEquals(12, graph.getNodes()); checkGraph(graph); assertEquals("named street1", graph.getEdgeIteratorState(iter1.getEdge(), iter1.getAdjNode()).getName()); assertEquals("named street2", graph.getEdgeIteratorState(iter2.getEdge(), iter2.getAdjNode()).getName()); graph.edge(3, 4, 123, true).setWayGeometry(Helper.createPointList3D(4.4, 5.5, 0, 6.6, 7.7, 0)); checkGraph(graph); }