Search in sources :

Example 6 with AllEdgesIterator

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

the class GHUtility method createSortedGraph.

static Graph createSortedGraph(Graph fromGraph, Graph toSortedGraph, final IntIndexedContainer oldToNewNodeList) {
    AllEdgesIterator eIter = fromGraph.getAllEdges();
    while (eIter.next()) {
        int base = eIter.getBaseNode();
        int newBaseIndex = oldToNewNodeList.get(base);
        int adj = eIter.getAdjNode();
        int newAdjIndex = oldToNewNodeList.get(adj);
        // ignore empty entries
        if (newBaseIndex < 0 || newAdjIndex < 0)
            continue;
        eIter.copyPropertiesTo(toSortedGraph.edge(newBaseIndex, newAdjIndex));
    }
    int nodes = fromGraph.getNodes();
    NodeAccess na = fromGraph.getNodeAccess();
    NodeAccess sna = toSortedGraph.getNodeAccess();
    for (int old = 0; old < nodes; old++) {
        int newIndex = oldToNewNodeList.get(old);
        if (sna.is3D())
            sna.setNode(newIndex, na.getLatitude(old), na.getLongitude(old), na.getElevation(old));
        else
            sna.setNode(newIndex, na.getLatitude(old), na.getLongitude(old));
    }
    return toSortedGraph;
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator)

Example 7 with AllEdgesIterator

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

the class GHUtility method copyTo.

/**
     * @return the specified toGraph which is now filled with data from fromGraph
     */
// TODO very similar to createSortedGraph -> use a 'int map(int)' interface
public static Graph copyTo(Graph fromGraph, Graph toGraph) {
    AllEdgesIterator eIter = fromGraph.getAllEdges();
    while (eIter.next()) {
        int base = eIter.getBaseNode();
        int adj = eIter.getAdjNode();
        eIter.copyPropertiesTo(toGraph.edge(base, adj));
    }
    NodeAccess fna = fromGraph.getNodeAccess();
    NodeAccess tna = toGraph.getNodeAccess();
    int nodes = fromGraph.getNodes();
    for (int node = 0; node < nodes; node++) {
        if (tna.is3D())
            tna.setNode(node, fna.getLatitude(node), fna.getLongitude(node), fna.getElevation(node));
        else
            tna.setNode(node, fna.getLatitude(node), fna.getLongitude(node));
    }
    return toGraph;
}
Also used : 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