use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method createLocationResult.
public QueryResult createLocationResult(double lat, double lon, EdgeIteratorState edge, int wayIndex, QueryResult.Position pos) {
if (edge == null)
throw new IllegalStateException("Specify edge != null");
QueryResult tmp = new QueryResult(lat, lon);
tmp.setClosestEdge(edge);
tmp.setWayIndex(wayIndex);
tmp.setSnappedPosition(pos);
tmp.calcSnappedPoint(new DistanceCalcEarth());
return tmp;
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testFillVirtualEdges.
@Test
public void testFillVirtualEdges() {
initGraph(g);
g.getNodeAccess().setNode(3, 0, 1);
g.edge(1, 3);
final int baseNode = 1;
EdgeIterator iter = g.createEdgeExplorer().setBaseNode(baseNode);
iter.next();
QueryResult res1 = createLocationResult(2, 1.7, iter, 1, PILLAR);
QueryGraph queryGraph = new QueryGraph(g) {
@Override
void fillVirtualEdges(IntObjectMap<VirtualEdgeIterator> node2Edge, int towerNode, EdgeExplorer mainExpl) {
super.fillVirtualEdges(node2Edge, towerNode, mainExpl);
// ignore nodes should include baseNode == 1
if (towerNode == 3)
assertEquals("[3->4]", node2Edge.get(towerNode).toString());
else if (towerNode == 1)
assertEquals("[1->4, 1 1-0]", node2Edge.get(towerNode).toString());
else
throw new IllegalStateException("not allowed " + towerNode);
}
};
queryGraph.lookup(Arrays.asList(res1));
EdgeIteratorState state = GHUtility.getEdge(queryGraph, 0, 1);
assertEquals(4, state.fetchWayGeometry(3).size());
// fetch virtual edge and check way geometry
state = GHUtility.getEdge(queryGraph, 4, 3);
assertEquals(2, state.fetchWayGeometry(3).size());
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testOneWay.
@Test
public void testOneWay() {
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0, 0);
na.setNode(1, 0, 1);
g.edge(0, 1, 10, false);
EdgeIteratorState edge = GHUtility.getEdge(g, 0, 1);
QueryResult res1 = createLocationResult(0.1, 0.1, edge, 0, EDGE);
QueryResult res2 = createLocationResult(0.1, 0.9, edge, 0, EDGE);
QueryGraph queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(res2, res1));
assertEquals(2, res1.getClosestNode());
assertEquals(new GHPoint(0, 0.1), res1.getSnappedPoint());
assertEquals(3, res2.getClosestNode());
assertEquals(new GHPoint(0, 0.9), res2.getSnappedPoint());
assertEquals(2, getPoints(queryGraph, 0, 2).getSize());
assertEquals(2, getPoints(queryGraph, 2, 3).getSize());
assertEquals(2, getPoints(queryGraph, 3, 1).getSize());
assertNull(GHUtility.getEdge(queryGraph, 3, 0));
assertNull(GHUtility.getEdge(queryGraph, 2, 1));
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class GraphHopperStorageCHTest method createQR.
QueryResult createQR(double lat, double lon, int wayIndex, EdgeIteratorState edge) {
QueryResult res = new QueryResult(lat, lon);
res.setClosestEdge(edge);
res.setWayIndex(wayIndex);
res.setSnappedPosition(QueryResult.Position.EDGE);
res.calcSnappedPoint(Helper.DIST_PLANE);
return res;
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class AbstractRoutingAlgorithmTester method calcPathViaQuery.
Path calcPathViaQuery(Weighting weighting, GraphHopperStorage ghStorage, double fromLat, double fromLon, double toLat, double toLon) {
LocationIndex index = new LocationIndexTree(ghStorage, new RAMDirectory());
index.prepareIndex();
QueryResult from = index.findClosest(fromLat, fromLon, EdgeFilter.ALL_EDGES);
QueryResult to = index.findClosest(toLat, toLon, EdgeFilter.ALL_EDGES);
// correct order for CH: in factory do prepare and afterwards wrap in query graph
AlgorithmOptions opts = AlgorithmOptions.start().weighting(weighting).build();
RoutingAlgorithmFactory factory = createFactory(ghStorage, opts);
QueryGraph qGraph = new QueryGraph(getGraph(ghStorage, weighting)).lookup(from, to);
return factory.createAlgo(qGraph, opts).calcPath(from.getClosestNode(), to.getClosestNode());
}
Aggregations