use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class GraphEdgeIdFinder method findEdgesInShape.
/**
* This method fills the edgeIds hash with edgeIds found inside the specified shape
*/
public void findEdgesInShape(final GHIntHashSet edgeIds, final Shape shape, EdgeFilter filter) {
GHPoint center = shape.getCenter();
QueryResult qr = locationIndex.findClosest(center.getLat(), center.getLon(), filter);
// TODO: if there is no street close to the center it'll fail although there are roads covered. Maybe we should check edge points or some random points in the Shape instead?
if (!qr.isValid())
throw new IllegalArgumentException("Shape " + shape + " does not cover graph");
if (shape.contains(qr.getSnappedPoint().lat, qr.getSnappedPoint().lon))
edgeIds.add(qr.getClosestEdge().getEdge());
BreadthFirstSearch bfs = new BreadthFirstSearch() {
final NodeAccess na = graph.getNodeAccess();
final Shape localShape = shape;
@Override
protected boolean goFurther(int nodeId) {
return localShape.contains(na.getLatitude(nodeId), na.getLongitude(nodeId));
}
@Override
protected boolean checkAdjacent(EdgeIteratorState edge) {
if (localShape.contains(na.getLatitude(edge.getAdjNode()), na.getLongitude(edge.getAdjNode()))) {
edgeIds.add(edge.getEdge());
return true;
}
return false;
}
};
bfs.start(graph.createEdgeExplorer(filter), qr.getClosestNode());
}
use of com.graphhopper.storage.index.QueryResult in project PocketMaps by junjunguo.
the class NaviEngine method findClosestStreet.
private GeoPoint findClosestStreet(GeoPoint fromPos) {
QueryResult pos = MapHandler.getMapHandler().getHopper().getLocationIndex().findClosest(fromPos.getLatitude(), fromPos.getLongitude(), EdgeFilter.ALL_EDGES);
int n = pos.getClosestEdge().getBaseNode();
NodeAccess nodeAccess = MapHandler.getMapHandler().getHopper().getGraphHopperStorage().getNodeAccess();
GeoPoint gp = new GeoPoint(nodeAccess.getLat(n), nodeAccess.getLon(n));
return gp;
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testGetEdgeProps.
@Test
public void testGetEdgeProps() {
initGraph(g);
EdgeIteratorState e1 = GHUtility.getEdge(g, 0, 2);
QueryGraph queryGraph = new QueryGraph(g);
QueryResult res1 = createLocationResult(0.5, 0, e1, 0, EDGE);
queryGraph.lookup(Arrays.asList(res1));
// get virtual edge
e1 = GHUtility.getEdge(queryGraph, res1.getClosestNode(), 0);
EdgeIteratorState e2 = queryGraph.getEdgeIteratorState(e1.getEdge(), Integer.MIN_VALUE);
assertEquals(e1.getEdge(), e2.getEdge());
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testInternalAPIOriginalTraversalKey.
@Test
public void testInternalAPIOriginalTraversalKey() {
initGraph(g);
EdgeExplorer explorer = g.createEdgeExplorer();
QueryGraph queryGraph = new QueryGraph(g);
EdgeIterator iter = explorer.setBaseNode(1);
assertTrue(iter.next());
int origEdgeId = iter.getEdge();
QueryResult res = createLocationResult(2, 1.5, iter, 1, PILLAR);
queryGraph.lookup(Arrays.asList(res));
assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
assertEquals(3, res.getClosestNode());
EdgeExplorer qGraphExplorer = queryGraph.createEdgeExplorer();
iter = qGraphExplorer.setBaseNode(3);
assertTrue(iter.next());
assertEquals(0, iter.getAdjNode());
assertEquals(GHUtility.createEdgeKey(1, 0, origEdgeId, false), ((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), 0)).getOriginalTraversalKey());
assertTrue(iter.next());
assertEquals(1, iter.getAdjNode());
assertEquals(GHUtility.createEdgeKey(0, 1, origEdgeId, false), ((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), 1)).getOriginalTraversalKey());
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method useEECache.
@Test
public void useEECache() {
initGraph(g);
EdgeExplorer explorer = g.createEdgeExplorer();
EdgeIterator iter = explorer.setBaseNode(1);
assertTrue(iter.next());
QueryResult res = createLocationResult(2, 1.5, iter, 1, PILLAR);
QueryGraph queryGraph = new QueryGraph(g).setUseEdgeExplorerCache(true);
queryGraph.lookup(Arrays.asList(res));
EdgeExplorer edgeExplorer = queryGraph.createEdgeExplorer();
// using cache means same reference
assertTrue(edgeExplorer == queryGraph.createEdgeExplorer());
}
Aggregations