Search in sources :

Example 1 with AllEdgesIterator

use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.

the class AbstractEdgeElevationInterpolator method interpolateElevationsOfTowerNodes.

private void interpolateElevationsOfTowerNodes() {
    final AllEdgesIterator edge = storage.getAllEdges();
    final GHBitSet visitedEdgeIds = new GHBitSetImpl(edge.getMaxId());
    final EdgeExplorer edgeExplorer = storage.createEdgeExplorer();
    while (edge.next()) {
        final int edgeId = edge.getEdge();
        if (isInterpolatableEdge(edge)) {
            if (!visitedEdgeIds.contains(edgeId)) {
                interpolateEdge(edge, visitedEdgeIds, edgeExplorer);
            }
        }
        visitedEdgeIds.add(edgeId);
    }
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) GHBitSet(com.graphhopper.coll.GHBitSet) EdgeExplorer(com.graphhopper.util.EdgeExplorer)

Example 2 with AllEdgesIterator

use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.

the class Location2IDFullWithEdgesIndex method findClosest.

@Override
public QueryResult findClosest(double queryLat, double queryLon, EdgeFilter filter) {
    if (isClosed())
        throw new IllegalStateException("You need to create a new LocationIndex instance as it is already closed");
    QueryResult res = new QueryResult(queryLat, queryLon);
    double foundDist = Double.MAX_VALUE;
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        if (!filter.accept(iter)) {
            continue;
        }
        for (int i = 0, node; i < 2; i++) {
            if (i == 0) {
                node = iter.getBaseNode();
            } else {
                node = iter.getAdjNode();
            }
            double fromLat = nodeAccess.getLatitude(node);
            double fromLon = nodeAccess.getLongitude(node);
            double fromDist = calc.calcDist(fromLat, fromLon, queryLat, queryLon);
            if (fromDist < 0)
                continue;
            if (fromDist < foundDist) {
                res.setQueryDistance(fromDist);
                res.setClosestEdge(iter.detach(false));
                res.setClosestNode(node);
                foundDist = fromDist;
            }
            // process the next stuff only for baseNode
            if (i > 0)
                continue;
            int toNode = iter.getAdjNode();
            double toLat = nodeAccess.getLatitude(toNode);
            double toLon = nodeAccess.getLongitude(toNode);
            if (calc.validEdgeDistance(queryLat, queryLon, fromLat, fromLon, toLat, toLon)) {
                double distEdge = calc.calcDenormalizedDist(calc.calcNormalizedEdgeDistance(queryLat, queryLon, fromLat, fromLon, toLat, toLon));
                if (distEdge < foundDist) {
                    res.setQueryDistance(distEdge);
                    res.setClosestNode(node);
                    res.setClosestEdge(iter);
                    if (fromDist > calc.calcDist(toLat, toLon, queryLat, queryLon))
                        res.setClosestNode(toNode);
                    foundDist = distEdge;
                }
            }
        }
    }
    return res;
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator)

Example 3 with AllEdgesIterator

use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.

the class GHUtility method printEdgeInfo.

public static void printEdgeInfo(final Graph g, FlagEncoder encoder) {
    System.out.println("-- Graph n:" + g.getNodes() + " e:" + g.getAllEdges().getMaxId() + " ---");
    AllEdgesIterator iter = g.getAllEdges();
    while (iter.next()) {
        String sc = "";
        if (iter instanceof AllCHEdgesIterator) {
            AllCHEdgesIterator aeSkip = (AllCHEdgesIterator) iter;
            sc = aeSkip.isShortcut() ? "sc" : "  ";
        }
        String fwdStr = iter.isForward(encoder) ? "fwd" : "   ";
        String bckStr = iter.isBackward(encoder) ? "bckwd" : "";
        System.out.println(sc + " " + iter + " " + fwdStr + " " + bckStr);
    }
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) AllCHEdgesIterator(com.graphhopper.routing.util.AllCHEdgesIterator)

Example 4 with AllEdgesIterator

use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.

the class ChangeGraphHelperTest method testApplyChanges.

@Test
public void testApplyChanges() {
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    FlagEncoder encoder = encodingManager.getEncoder("car");
    double defaultSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        long flags = GHUtility.getEdge(graph, 0, 1).getFlags();
        assertEquals(defaultSpeed, encoder.getSpeed(flags), .1);
        assertTrue(encoder.isForward(flags));
    }
    Reader reader = new InputStreamReader(getClass().getResourceAsStream("overlaydata1.json"), Helper.UTF_CS);
    ChangeGraphHelper instance = new ChangeGraphHelper(graph, locationIndex);
    JsonFeatureConverter converter = new JsonFeatureConverter(ghson, instance, encodingManager);
    long updates = converter.applyChanges(reader);
    assertEquals(2, updates);
    // assert changed speed and access
    double newSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
    assertEquals(10, newSpeed, .1);
    assertTrue(newSpeed < defaultSpeed);
    assertFalse(encoder.isForward(GHUtility.getEdge(graph, 3, 4).getFlags()));
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) InputStreamReader(java.io.InputStreamReader) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) JsonFeatureConverter(com.graphhopper.json.JsonFeatureConverter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) LocationIndex(com.graphhopper.storage.index.LocationIndex) RAMDirectory(com.graphhopper.storage.RAMDirectory) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.Test)

Example 5 with AllEdgesIterator

use of com.graphhopper.routing.util.AllEdgesIterator in project graphhopper by graphhopper.

the class Location2IDFullIndex method findClosest.

@Override
public QueryResult findClosest(double queryLat, double queryLon, EdgeFilter edgeFilter) {
    if (isClosed())
        throw new IllegalStateException("You need to create a new LocationIndex instance as it is already closed");
    QueryResult res = new QueryResult(queryLat, queryLon);
    Circle circle = null;
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        if (!edgeFilter.accept(iter))
            continue;
        for (int node, i = 0; i < 2; i++) {
            if (i == 0) {
                node = iter.getBaseNode();
            } else {
                node = iter.getAdjNode();
            }
            double tmpLat = nodeAccess.getLatitude(node);
            double tmpLon = nodeAccess.getLongitude(node);
            double dist = calc.calcDist(tmpLat, tmpLon, queryLat, queryLon);
            if (circle == null || dist < calc.calcDist(circle.getLat(), circle.getLon(), queryLat, queryLon)) {
                res.setClosestEdge(iter.detach(false));
                res.setClosestNode(node);
                res.setQueryDistance(dist);
                if (dist <= 0)
                    break;
                circle = new Circle(tmpLat, tmpLon, dist, calc);
            }
        }
    }
    return res;
}
Also used : Circle(com.graphhopper.util.shapes.Circle) AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator)

Aggregations

AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)7 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHBitSetImpl (com.graphhopper.coll.GHBitSetImpl)1 JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 AllCHEdgesIterator (com.graphhopper.routing.util.AllCHEdgesIterator)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 RAMDirectory (com.graphhopper.storage.RAMDirectory)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 EdgeExplorer (com.graphhopper.util.EdgeExplorer)1 Circle (com.graphhopper.util.shapes.Circle)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Test (org.junit.Test)1