Search in sources :

Example 26 with QueryResult

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;
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult)

Example 27 with QueryResult

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());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) IntObjectMap(com.carrotsearch.hppc.IntObjectMap) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 28 with QueryResult

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));
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 29 with QueryResult

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;
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult)

Example 30 with QueryResult

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());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) LocationIndex(com.graphhopper.storage.index.LocationIndex) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree)

Aggregations

QueryResult (com.graphhopper.storage.index.QueryResult)39 GHPoint (com.graphhopper.util.shapes.GHPoint)20 Test (org.junit.Test)20 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 LocationIndex (com.graphhopper.storage.index.LocationIndex)4 Weighting (com.graphhopper.routing.weighting.Weighting)3 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)3 GHRequest (com.graphhopper.GHRequest)2 GHResponse (com.graphhopper.GHResponse)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)2 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 Stop (com.conveyal.gtfs.model.Stop)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GraphHopper (com.graphhopper.GraphHopper)1 GHIntObjectHashMap (com.graphhopper.coll.GHIntObjectHashMap)1