Search in sources :

Example 1 with NodeAccess

use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.

the class AbstractEdgeElevationInterpolator method interpolateElevationsOfPillarNodes.

private void interpolateElevationsOfPillarNodes() {
    final EdgeIterator edge = storage.getAllEdges();
    final NodeAccess nodeAccess = storage.getNodeAccess();
    while (edge.next()) {
        if (isInterpolatableEdge(edge)) {
            int firstNodeId = edge.getBaseNode();
            int secondNodeId = edge.getAdjNode();
            double lat0 = nodeAccess.getLat(firstNodeId);
            double lon0 = nodeAccess.getLon(firstNodeId);
            double ele0 = nodeAccess.getEle(firstNodeId);
            double lat1 = nodeAccess.getLat(secondNodeId);
            double lon1 = nodeAccess.getLon(secondNodeId);
            double ele1 = nodeAccess.getEle(secondNodeId);
            final PointList pointList = edge.fetchWayGeometry(0);
            final int count = pointList.size();
            for (int index = 0; index < count; index++) {
                double lat = pointList.getLat(index);
                double lon = pointList.getLon(index);
                double ele = elevationInterpolator.calculateElevationBasedOnTwoPoints(lat, lon, lat0, lon0, ele0, lat1, lon1, ele1);
                pointList.set(index, lat, lon, ele);
            }
            edge.setWayGeometry(pointList);
        }
    }
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) PointList(com.graphhopper.util.PointList) NodeAccess(com.graphhopper.storage.NodeAccess)

Example 2 with NodeAccess

use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.

the class NodeElevationInterpolator method interpolateElevationsOfInnerNodesForOneOuterNode.

private void interpolateElevationsOfInnerNodesForOneOuterNode(int outerNodeId, int[] innerNodeIds) {
    NodeAccess nodeAccess = storage.getNodeAccess();
    double ele = nodeAccess.getEle(outerNodeId);
    for (int innerNodeId : innerNodeIds) {
        double lat = nodeAccess.getLat(innerNodeId);
        double lon = nodeAccess.getLon(innerNodeId);
        nodeAccess.setNode(innerNodeId, lat, lon, ele);
    }
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess)

Example 3 with NodeAccess

use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.

the class NodeElevationInterpolator method interpolateElevationsOfInnerNodesForTwoOuterNodes.

private void interpolateElevationsOfInnerNodesForTwoOuterNodes(int firstOuterNodeId, int secondOuterNodeId, int[] innerNodeIds) {
    final NodeAccess nodeAccess = storage.getNodeAccess();
    double lat0 = nodeAccess.getLat(firstOuterNodeId);
    double lon0 = nodeAccess.getLon(firstOuterNodeId);
    double ele0 = nodeAccess.getEle(firstOuterNodeId);
    double lat1 = nodeAccess.getLat(secondOuterNodeId);
    double lon1 = nodeAccess.getLon(secondOuterNodeId);
    double ele1 = nodeAccess.getEle(secondOuterNodeId);
    for (int innerNodeId : innerNodeIds) {
        double lat = nodeAccess.getLat(innerNodeId);
        double lon = nodeAccess.getLon(innerNodeId);
        double ele = elevationInterpolator.calculateElevationBasedOnTwoPoints(lat, lon, lat0, lon0, ele0, lat1, lon1, ele1);
        nodeAccess.setNode(innerNodeId, lat, lon, ele);
    }
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess)

Example 4 with NodeAccess

use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.

the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithFourOuterNodes.

@Test
public void interpolatesElevationOfTunnelWithFourOuterNodes() {
    // @formatter:off
    /*
            * Graph structure:
            * 0-----1--T--2--T--3-----4
            *             |
            *             |
            *             T
            *             |
            *             |
            * 5-----6--T--7--T--8-----9
         */
    // @formatter:on
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 0, 0);
    na.setNode(1, 10, 0, 10);
    na.setNode(2, 20, 0, 1000);
    na.setNode(3, 30, 0, 30);
    na.setNode(4, 40, 0, 40);
    na.setNode(5, 0, 10, 40);
    na.setNode(6, 10, 10, 30);
    na.setNode(7, 20, 10, 1000);
    na.setNode(8, 30, 10, 10);
    na.setNode(9, 40, 10, 0);
    EdgeIteratorState edge01 = graph.edge(0, 1, 10, true);
    EdgeIteratorState edge12 = graph.edge(1, 2, 10, true);
    EdgeIteratorState edge23 = graph.edge(2, 3, 10, true);
    EdgeIteratorState edge34 = graph.edge(3, 4, 10, true);
    EdgeIteratorState edge56 = graph.edge(5, 6, 10, true);
    EdgeIteratorState edge67 = graph.edge(6, 7, 10, true);
    EdgeIteratorState edge78 = graph.edge(7, 8, 10, true);
    EdgeIteratorState edge89 = graph.edge(8, 9, 10, true);
    EdgeIteratorState edge27 = graph.edge(2, 7, 10, true);
    edge01.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge12.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge23.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge34.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge56.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge67.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge78.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge89.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge27.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge12, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(1, 3, 6, 8), outerNodeIds);
    assertEquals(GHIntHashSet.from(2, 7), innerNodeIds);
    edgeElevationInterpolator.execute();
    assertEquals(0, na.getElevation(0), PRECISION);
    assertEquals(10, na.getElevation(1), PRECISION);
    assertEquals(20, na.getElevation(2), PRECISION);
    assertEquals(30, na.getElevation(3), PRECISION);
    assertEquals(40, na.getElevation(4), PRECISION);
    assertEquals(40, na.getElevation(5), PRECISION);
    assertEquals(30, na.getElevation(6), PRECISION);
    assertEquals(20, na.getElevation(7), PRECISION);
    assertEquals(10, na.getElevation(8), PRECISION);
    assertEquals(0, na.getElevation(9), PRECISION);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 5 with NodeAccess

use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.

the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithThreeOuterNodes.

@Test
public void interpolatesElevationOfTunnelWithThreeOuterNodes() {
    // @formatter:off
    /*
		 * Graph structure:
		 * 0-----1--T--2--T--3-----4
		 *             |
		 *             |
		 *             T
		 *             |
		 *             |
		 *             5--T--6-----7
         */
    // @formatter:on
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 0, 0);
    na.setNode(1, 10, 0, 10);
    na.setNode(2, 20, 0, 1000);
    na.setNode(3, 30, 0, 30);
    na.setNode(4, 40, 0, 40);
    na.setNode(5, 20, 10, 1000);
    na.setNode(6, 30, 10, 30);
    na.setNode(7, 40, 10, 40);
    EdgeIteratorState edge01 = graph.edge(0, 1, 10, true);
    EdgeIteratorState edge12 = graph.edge(1, 2, 10, true);
    EdgeIteratorState edge23 = graph.edge(2, 3, 10, true);
    EdgeIteratorState edge34 = graph.edge(3, 4, 10, true);
    EdgeIteratorState edge25 = graph.edge(2, 5, 10, true);
    EdgeIteratorState edge56 = graph.edge(5, 6, 10, true);
    EdgeIteratorState edge67 = graph.edge(6, 7, 10, true);
    edge01.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge12.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge23.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge34.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge25.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge56.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge67.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge12, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(1, 3, 6), outerNodeIds);
    assertEquals(GHIntHashSet.from(2, 5), innerNodeIds);
    edgeElevationInterpolator.execute();
    assertEquals(0, na.getElevation(0), PRECISION);
    assertEquals(10, na.getElevation(1), PRECISION);
    assertEquals(20, na.getElevation(2), PRECISION);
    assertEquals(30, na.getElevation(3), PRECISION);
    assertEquals(40, na.getElevation(4), PRECISION);
    assertEquals(20, na.getElevation(5), PRECISION);
    assertEquals(30, na.getElevation(6), PRECISION);
    assertEquals(40, na.getElevation(7), PRECISION);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Aggregations

NodeAccess (com.graphhopper.storage.NodeAccess)27 Test (org.junit.Test)16 Graph (com.graphhopper.storage.Graph)14 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)6 GraphBuilder (com.graphhopper.storage.GraphBuilder)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 Dijkstra (com.graphhopper.routing.Dijkstra)5 Path (com.graphhopper.routing.Path)5 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)5 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 PointList (com.graphhopper.util.PointList)4 GHRequest (com.graphhopper.GHRequest)2 GHResponse (com.graphhopper.GHResponse)2 CHGraph (com.graphhopper.storage.CHGraph)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 Random (java.util.Random)2 PathWrapper (com.graphhopper.PathWrapper)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 EdgeIterator (com.graphhopper.util.EdgeIterator)1 IOException (java.io.IOException)1