Search in sources :

Example 26 with NodeAccess

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

the class GraphHopperAPITest method initGraph.

void initGraph(GraphHopperStorage graph) {
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 42, 10);
    na.setNode(1, 42.1, 10.1);
    na.setNode(2, 42.1, 10.2);
    na.setNode(3, 42, 10.4);
    graph.edge(0, 1, 10, true);
    graph.edge(2, 3, 10, true);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess)

Example 27 with NodeAccess

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

the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithSingleOuterNode.

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

Example 28 with NodeAccess

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

the class TunnelElevationInterpolatorTest method doesNotInterpolateElevationOfTunnelWithZeroOuterNodes.

@Test
public void doesNotInterpolateElevationOfTunnelWithZeroOuterNodes() {
    // @formatter:off
    /*
         * Graph structure:
		 * 0--T--1--T--2     3--T--4
		 * Tunnel 0-1-2 has a single outer node 2.
         */
    // @formatter:on
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0, 0, 0);
    na.setNode(1, 10, 0, 0);
    na.setNode(2, 20, 0, 10);
    na.setNode(3, 30, 0, 20);
    na.setNode(4, 40, 0, 0);
    EdgeIteratorState edge01 = graph.edge(0, 1, 10, true);
    EdgeIteratorState edge12 = graph.edge(1, 2, 10, true);
    EdgeIteratorState edge34 = graph.edge(3, 4, 10, true);
    edge01.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge12.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge34.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge01, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(), outerNodeIds);
    assertEquals(GHIntHashSet.from(0, 1, 2), innerNodeIds);
    edgeElevationInterpolator.execute();
    assertEquals(0, na.getElevation(0), PRECISION);
    assertEquals(0, na.getElevation(1), PRECISION);
    assertEquals(10, na.getElevation(2), PRECISION);
    assertEquals(20, na.getElevation(3), PRECISION);
    assertEquals(0, na.getElevation(4), PRECISION);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 29 with NodeAccess

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

the class TunnelElevationInterpolatorTest method interpolatesElevationOfTunnelWithTwoOuterNodes.

@Test
public void interpolatesElevationOfTunnelWithTwoOuterNodes() {
    // @formatter:off
    /*
		 * Graph structure:
		 * 0-----1--T--2--T--3-----4
         */
    // @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);
    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);
    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));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge12, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(1, 3), outerNodeIds);
    assertEquals(GHIntHashSet.from(2), 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);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 30 with NodeAccess

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

the class NodeElevationInterpolator method interpolateElevationsOfInnerNodesForNOuterNodes.

private void interpolateElevationsOfInnerNodesForNOuterNodes(int[] outerNodeIds, int[] innerNodeIds) {
    NodeAccess nodeAccess = storage.getNodeAccess();
    PointList pointList = new PointList(outerNodeIds.length, true);
    for (int outerNodeId : outerNodeIds) {
        pointList.add(nodeAccess.getLat(outerNodeId), nodeAccess.getLon(outerNodeId), nodeAccess.getEle(outerNodeId));
    }
    for (int innerNodeId : innerNodeIds) {
        double lat = nodeAccess.getLat(innerNodeId);
        double lon = nodeAccess.getLon(innerNodeId);
        double ele = elevationInterpolator.calculateElevationBasedOnPointList(lat, lon, pointList);
        nodeAccess.setNode(innerNodeId, lat, lon, ele);
    }
}
Also used : PointList(com.graphhopper.util.PointList) NodeAccess(com.graphhopper.storage.NodeAccess)

Aggregations

NodeAccess (com.graphhopper.storage.NodeAccess)31 Graph (com.graphhopper.storage.Graph)18 Test (org.junit.Test)18 GraphBuilder (com.graphhopper.storage.GraphBuilder)7 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)7 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)6 Dijkstra (com.graphhopper.routing.Dijkstra)6 Path (com.graphhopper.routing.Path)6 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)6 RAMDirectory (com.graphhopper.storage.RAMDirectory)5 PointList (com.graphhopper.util.PointList)5 GHRequest (com.graphhopper.GHRequest)3 GHResponse (com.graphhopper.GHResponse)3 CHGraph (com.graphhopper.storage.CHGraph)3 PathWrapper (com.graphhopper.PathWrapper)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 ArrayList (java.util.ArrayList)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1