use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class TunnelElevationInterpolatorTest method doesNotInterpolateElevationOfTunnelWithZeroOuterNodes.
@Test
public void doesNotInterpolateElevationOfTunnelWithZeroOuterNodes() {
// @formatter:off
/*
* Graph structure:
* 0--T--1--T--2 3--T--4
* Tunnel 0-1-2 has a single outer node 2.
*/
// @formatter:on
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0, 0, 0);
na.setNode(1, 10, 0, 0);
na.setNode(2, 20, 0, 10);
na.setNode(3, 30, 0, 20);
na.setNode(4, 40, 0, 0);
EdgeIteratorState edge01 = graph.edge(0, 1, 10, true);
EdgeIteratorState edge12 = graph.edge(1, 2, 10, true);
EdgeIteratorState edge34 = graph.edge(3, 4, 10, true);
edge01.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge12.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge34.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
final GHIntHashSet outerNodeIds = new GHIntHashSet();
final GHIntHashSet innerNodeIds = new GHIntHashSet();
gatherOuterAndInnerNodeIdsOfStructure(edge01, outerNodeIds, innerNodeIds);
assertEquals(GHIntHashSet.from(), outerNodeIds);
assertEquals(GHIntHashSet.from(0, 1, 2), innerNodeIds);
edgeElevationInterpolator.execute();
assertEquals(0, na.getElevation(0), PRECISION);
assertEquals(0, na.getElevation(1), PRECISION);
assertEquals(10, na.getElevation(2), PRECISION);
assertEquals(20, na.getElevation(3), PRECISION);
assertEquals(0, na.getElevation(4), PRECISION);
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithTwoOuterNodes.
@Test
public void interpolatesElevationOfTunnelWithTwoOuterNodes() {
// @formatter:off
/*
* Graph structure:
* 0-----1--T--2--T--3-----4
*/
// @formatter:on
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0, 0, 0);
na.setNode(1, 10, 0, 10);
na.setNode(2, 20, 0, 1000);
na.setNode(3, 30, 0, 30);
na.setNode(4, 40, 0, 40);
EdgeIteratorState edge01 = graph.edge(0, 1, 10, true);
EdgeIteratorState edge12 = graph.edge(1, 2, 10, true);
EdgeIteratorState edge23 = graph.edge(2, 3, 10, true);
EdgeIteratorState edge34 = graph.edge(3, 4, 10, true);
edge01.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge12.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge23.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge34.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
final GHIntHashSet outerNodeIds = new GHIntHashSet();
final GHIntHashSet innerNodeIds = new GHIntHashSet();
gatherOuterAndInnerNodeIdsOfStructure(edge12, outerNodeIds, innerNodeIds);
assertEquals(GHIntHashSet.from(1, 3), outerNodeIds);
assertEquals(GHIntHashSet.from(2), innerNodeIds);
edgeElevationInterpolator.execute();
assertEquals(0, na.getElevation(0), PRECISION);
assertEquals(10, na.getElevation(1), PRECISION);
assertEquals(20, na.getElevation(2), PRECISION);
assertEquals(30, na.getElevation(3), PRECISION);
assertEquals(40, na.getElevation(4), PRECISION);
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class InstructionListTest method testInstructionsWithTimeAndPlace.
@Test
public void testInstructionsWithTimeAndPlace() {
Graph g = new GraphBuilder(carManager).create();
// 4-5
// |
// 3-2
// |
// 1
NodeAccess na = g.getNodeAccess();
na.setNode(1, 15.0, 10);
na.setNode(2, 15.1, 10);
na.setNode(3, 15.1, 9.9);
na.setNode(4, 15.2, 9.9);
na.setNode(5, 15.2, 10);
g.edge(1, 2, 7000, true).setName("1-2").setFlags(flagsForSpeed(carManager, 70));
g.edge(2, 3, 8000, true).setName("2-3").setFlags(flagsForSpeed(carManager, 80));
g.edge(3, 4, 9000, true).setName("3-4").setFlags(flagsForSpeed(carManager, 90));
g.edge(4, 5, 10000, true).setName("4-5").setFlags(flagsForSpeed(carManager, 100));
Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(1, 5);
InstructionList wayList = p.calcInstructions(usTR);
assertEquals(5, wayList.size());
List<GPXEntry> gpxList = wayList.createGPXList();
assertEquals(34000, p.getDistance(), 1e-1);
assertEquals(34000, sumDistances(wayList), 1e-1);
assertEquals(5, gpxList.size());
assertEquals(1604120, p.getTime());
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);
assertEquals(Instruction.TURN_RIGHT, wayList.get(3).getSign());
assertEquals(15.2, wayList.get(3).getFirstLat(), 1e-3);
assertEquals(9.9, wayList.get(3).getFirstLon(), 1e-3);
String gpxStr = wayList.createGPX("test", 0);
verifyGPX(gpxStr);
assertTrue(gpxStr, gpxStr.contains("<trkpt lat=\"15.0\" lon=\"10.0\"><time>1970-01-01T00:00:00Z</time>"));
assertTrue(gpxStr, gpxStr.contains("<extensions>") && gpxStr.contains("</extensions>"));
assertTrue(gpxStr, gpxStr.contains("<rtept lat=\"15.1\" lon=\"10.0\">"));
assertTrue(gpxStr, gpxStr.contains("<gh:distance>8000.0</gh:distance>"));
assertTrue(gpxStr, gpxStr.contains("<desc>turn left onto 2-3</desc>"));
assertTrue(gpxStr, gpxStr.contains("<gh:sign>-2</gh:sign>"));
assertTrue(gpxStr, gpxStr.contains("<gh:direction>N</gh:direction>"));
assertTrue(gpxStr, gpxStr.contains("<gh:azimuth>0.0</gh:azimuth>"));
assertFalse(gpxStr, gpxStr.contains("NaN"));
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class InstructionListTest method testFind.
@Test
public void testFind() {
Graph g = new GraphBuilder(carManager).create();
// n-4-5 (n: pillar node)
// |
// 3-2
// |
// 1
NodeAccess na = g.getNodeAccess();
na.setNode(1, 15.0, 10);
na.setNode(2, 15.1, 10);
na.setNode(3, 15.1, 9.9);
PointList waypoint = new PointList();
waypoint.add(15.2, 9.9);
na.setNode(4, 15.2, 10);
na.setNode(5, 15.2, 10.1);
g.edge(1, 2, 10000, true).setName("1-2");
g.edge(2, 3, 10000, true).setName("2-3");
g.edge(3, 4, 10000, true).setName("3-4").setWayGeometry(waypoint);
g.edge(4, 5, 10000, true).setName("4-5");
Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(1, 5);
InstructionList wayList = p.calcInstructions(usTR);
// query on first edge, get instruction for second edge
assertEquals("2-3", wayList.find(15.05, 10, 1000).getName());
// query east of first edge, get instruction for second edge
assertEquals("2-3", wayList.find(15.05, 10.001, 1000).getName());
// query south-west of node 3, get instruction for third edge
assertEquals("3-4", wayList.find(15.099, 9.9, 1000).getName());
// query north-west of pillar node n , get instruction for fourth edge
assertEquals("4-5", wayList.find(15.21, 9.85, 100000).getName());
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class LocationIndexTreeTest method createTestGraphWithWayGeometry.
// -1 0 1 1.5
// --------------------
// 1| --A
// | -0--/ \
// 0| / | B-\ \
// | / 1/ 3--4
// | |/------/ /
//-1| 2---------/
// |
private Graph createTestGraphWithWayGeometry() {
Graph graph = createGHStorage(encodingManager);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0.5, -0.5);
na.setNode(1, -0.5, -0.5);
na.setNode(2, -1, -1);
na.setNode(3, -0.4, 0.9);
na.setNode(4, -0.6, 1.6);
graph.edge(0, 1, 1, true);
graph.edge(0, 2, 1, true);
// insert A and B, without this we would get 0 for 0,0
graph.edge(0, 4, 1, true).setWayGeometry(Helper.createPointList(1, 1));
graph.edge(1, 3, 1, true).setWayGeometry(Helper.createPointList(0, 0));
graph.edge(2, 3, 1, true);
graph.edge(2, 4, 1, true);
graph.edge(3, 4, 1, true);
return graph;
}
Aggregations