use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class QueryGraphTest method testOneVirtualNode.
@Test
public void testOneVirtualNode() {
initGraph(g);
EdgeExplorer expl = g.createEdgeExplorer();
// snap directly to tower node => pointList could get of size 1?!?
// a)
EdgeIterator iter = expl.setBaseNode(2);
iter.next();
Snap res = createLocationResult(1, -1, iter, 0, TOWER);
QueryGraph queryGraph0 = lookup(res);
assertEquals(new GHPoint(0, 0), res.getSnappedPoint());
// b)
res = createLocationResult(1, -1, iter, 1, TOWER);
QueryGraph queryGraph1 = lookup(res);
assertEquals(new GHPoint(1, 0), res.getSnappedPoint());
// c)
iter = expl.setBaseNode(1);
iter.next();
res = createLocationResult(1.2, 2.7, iter, 0, TOWER);
QueryGraph queryGraph2 = lookup(res);
assertEquals(new GHPoint(1, 2.5), res.getSnappedPoint());
// node number stays
assertEquals(3, queryGraph2.getNodes());
// snap directly to pillar node
iter = expl.setBaseNode(1);
iter.next();
res = createLocationResult(2, 1.5, iter, 1, PILLAR);
QueryGraph queryGraph3 = lookup(res);
assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
assertEquals(3, res.getClosestNode());
assertEquals(3, getPoints(queryGraph3, 0, 3).size());
assertEquals(2, getPoints(queryGraph3, 3, 1).size());
res = createLocationResult(2, 1.7, iter, 1, PILLAR);
QueryGraph queryGraph4 = lookup(res);
assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
assertEquals(3, res.getClosestNode());
assertEquals(3, getPoints(queryGraph4, 0, 3).size());
assertEquals(2, getPoints(queryGraph4, 3, 1).size());
// snap to edge which has pillar nodes
res = createLocationResult(1.5, 2, iter, 0, EDGE);
QueryGraph queryGraph5 = lookup(res);
assertEquals(new GHPoint(1.300019, 1.899962), res.getSnappedPoint());
assertEquals(3, res.getClosestNode());
assertEquals(4, getPoints(queryGraph5, 0, 3).size());
assertEquals(2, getPoints(queryGraph5, 3, 1).size());
// snap to edge which has no pillar nodes
iter = expl.setBaseNode(2);
iter.next();
res = createLocationResult(0.5, 0.1, iter, 0, EDGE);
QueryGraph queryGraph6 = lookup(res);
assertEquals(new GHPoint(0.5, 0), res.getSnappedPoint());
assertEquals(3, res.getClosestNode());
assertEquals(2, getPoints(queryGraph6, 0, 3).size());
assertEquals(2, getPoints(queryGraph6, 3, 2).size());
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class QueryGraphTest method testFillVirtualEdges.
@Test
public void testFillVirtualEdges() {
// x (4)
// /*-*\
// 0 1
// | /
// 2 3
NodeAccess na = g.getNodeAccess();
na.setNode(0, 1, 0);
na.setNode(1, 1, 2.5);
na.setNode(2, 0, 0);
na.setNode(3, 0, 1);
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 2).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(10)).setWayGeometry(Helper.createPointList(1.5, 1, 1.5, 1.5));
g.edge(1, 3);
final int baseNode = 1;
EdgeIterator iter = g.createEdgeExplorer().setBaseNode(baseNode);
iter.next();
// note that we do not really do a location index lookup, but rather create a snap artificially, also
// this snap is not very intuitive as we would expect snapping to the 1-0 edge, but this is how this
// test was written initially...
Snap snap = createLocationResult(2, 1.7, iter, 1, PILLAR);
QueryOverlay queryOverlay = QueryOverlayBuilder.build(g, Collections.singletonList(snap));
IntObjectMap<QueryOverlay.EdgeChanges> realNodeModifications = queryOverlay.getEdgeChangesAtRealNodes();
assertEquals(2, realNodeModifications.size());
// ignore nodes should include baseNode == 1
assertEquals("[3->4]", realNodeModifications.get(3).getAdditionalEdges().toString());
assertEquals("[2]", realNodeModifications.get(3).getRemovedEdges().toString());
assertEquals("[1->4]", realNodeModifications.get(1).getAdditionalEdges().toString());
assertEquals("[2]", realNodeModifications.get(1).getRemovedEdges().toString());
QueryGraph queryGraph = QueryGraph.create(g, snap);
EdgeIteratorState state = GHUtility.getEdge(queryGraph, 0, 1);
assertEquals(4, state.fetchWayGeometry(FetchMode.ALL).size());
// fetch virtual edge and check way geometry
state = GHUtility.getEdge(queryGraph, 4, 3);
assertEquals(2, state.fetchWayGeometry(FetchMode.ALL).size());
// now we actually test the edges at the real tower nodes (virtual ones should be added and some real ones removed)
assertEquals("[1->4, 1 1-0]", ((VirtualEdgeIterator) queryGraph.createEdgeExplorer().setBaseNode(1)).getEdges().toString());
assertEquals("[3->4]", ((VirtualEdgeIterator) queryGraph.createEdgeExplorer().setBaseNode(3)).getEdges().toString());
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class QueryGraphTest method testUseMeanElevation.
@Test
public void testUseMeanElevation() {
g.close();
g = new GraphBuilder(encodingManager).set3D(true).create();
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0, 0, 0);
na.setNode(1, 0, 0.0001, 20);
EdgeIteratorState edge = g.edge(0, 1);
EdgeIteratorState edgeReverse = edge.detach(true);
DistanceCalcEuclidean distCalc = new DistanceCalcEuclidean();
Snap snap = new Snap(0, 0.00005);
snap.setClosestEdge(edge);
snap.setWayIndex(0);
snap.setSnappedPosition(EDGE);
snap.calcSnappedPoint(distCalc);
assertEquals(10, snap.getSnappedPoint().getEle(), 1e-1);
snap = new Snap(0, 0.00005);
snap.setClosestEdge(edgeReverse);
snap.setWayIndex(0);
snap.setSnappedPosition(EDGE);
snap.calcSnappedPoint(distCalc);
assertEquals(10, snap.getSnappedPoint().getEle(), 1e-1);
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class QueryGraphTest method testLoopStreet_Issue151.
@Test
public void testLoopStreet_Issue151() {
// do query at x should result in ignoring only the bottom edge 1-3 not the upper one => getNeighbors are 0, 5, 3 and not only 0, 5
//
// 0--1--3--4
// | |
// x---
//
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 3).setDistance(10));
GHUtility.setSpeed(60, true, true, encoder, g.edge(3, 4).setDistance(10));
EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 3).setDistance(20)).setWayGeometry(Helper.createPointList(-0.001, 0.001, -0.001, 0.002));
updateDistancesFor(g, 0, 0, 0);
updateDistancesFor(g, 1, 0, 0.001);
updateDistancesFor(g, 3, 0, 0.002);
updateDistancesFor(g, 4, 0, 0.003);
Snap snap = new Snap(-0.0005, 0.001);
snap.setClosestEdge(edge);
snap.setWayIndex(1);
snap.calcSnappedPoint(new DistanceCalcEuclidean());
QueryGraph qg = lookup(snap);
EdgeExplorer ee = qg.createEdgeExplorer();
assertEquals(GHUtility.asSet(0, 5, 3), GHUtility.getNeighbors(ee.setBaseNode(1)));
}
use of com.graphhopper.storage.index.Snap in project graphhopper by graphhopper.
the class QueryGraphTest method testEdgesShareOneNode.
@Test
public void testEdgesShareOneNode() {
initGraph(g);
EdgeIteratorState iter = GHUtility.getEdge(g, 0, 2);
Snap res1 = createLocationResult(0.5, 0, iter, 0, EDGE);
iter = GHUtility.getEdge(g, 1, 0);
Snap res2 = createLocationResult(1.5, 2, iter, 0, EDGE);
QueryGraph queryGraph = lookup(Arrays.asList(res1, res2));
assertEquals(new GHPoint(0.5, 0), res1.getSnappedPoint());
assertEquals(new GHPoint(1.300019, 1.899962), res2.getSnappedPoint());
assertNotNull(GHUtility.getEdge(queryGraph, 0, 4));
assertNotNull(GHUtility.getEdge(queryGraph, 0, 3));
}
Aggregations