Search in sources :

Example 11 with PointList

use of com.graphhopper.util.PointList in project graphhopper by graphhopper.

the class ShapeFileReaderTest method testGeometrySingleEdgePath.

@Test
public void testGeometrySingleEdgePath() {
    // We choose a path along a single edge with a couple of minor bends,
    // which we expect to give identical results...
    FromToPair pair = new FromToPair(35.911694, 14.492303, 35.911494, 14.490489);
    PointList shp = pair.getPath(hopperShp, true).getPoints();
    PointList pbf = pair.getPath(hopperPbf, true).getPoints();
    assertTrue("The chosen edge had a couple of bends!", shp.getSize() >= 2);
    assertSameGeometry(shp, pbf);
}
Also used : PointList(com.graphhopper.util.PointList) Test(org.junit.Test)

Example 12 with PointList

use of com.graphhopper.util.PointList in project graphhopper by graphhopper.

the class BridgeElevationInterpolatorTest method interpolatesElevationOfPillarNodes.

@Test
public void interpolatesElevationOfPillarNodes() {
    // @formatter:off
    /*
         * Graph structure:
		 * 0-----1-----2-----3-----4
		 *        \    |    /
		 *         \   |   /
		 *          T  T  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, 20);
    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 edge17 = graph.edge(1, 7, 10, true);
    EdgeIteratorState edge27 = graph.edge(2, 7, 10, true);
    EdgeIteratorState edge37 = graph.edge(3, 7, 10, true);
    edge17.setWayGeometry(Helper.createPointList3D(12, 2, 200, 14, 4, 400, 16, 6, 600, 18, 8, 800));
    edge01.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge12.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
    edge23.setFlags(dataFlagEncoder.handleWayTags(normalWay, 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));
    edge17.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge27.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    edge37.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
    final GHIntHashSet outerNodeIds = new GHIntHashSet();
    final GHIntHashSet innerNodeIds = new GHIntHashSet();
    gatherOuterAndInnerNodeIdsOfStructure(edge27, outerNodeIds, innerNodeIds);
    assertEquals(GHIntHashSet.from(1, 2, 3, 6, 8), outerNodeIds);
    assertEquals(GHIntHashSet.from(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);
    final PointList edge17PointList = edge17.fetchWayGeometry(3);
    assertEquals(6, edge17PointList.size());
    assertEquals(10, edge17PointList.getEle(0), PRECISION);
    assertEquals(12, edge17PointList.getEle(1), PRECISION);
    assertEquals(14, edge17PointList.getEle(2), PRECISION);
    assertEquals(16, edge17PointList.getEle(3), PRECISION);
    assertEquals(18, edge17PointList.getEle(4), PRECISION);
    assertEquals(20, edge17PointList.getEle(5), PRECISION);
}
Also used : PointList(com.graphhopper.util.PointList) NodeAccess(com.graphhopper.storage.NodeAccess) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 13 with PointList

use of com.graphhopper.util.PointList in project graphhopper by graphhopper.

the class GraphHopperAPITest method testLoad.

@Test
public void testLoad() {
    GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
    initGraph(graph);
    // do further changes:
    NodeAccess na = graph.getNodeAccess();
    na.setNode(4, 41.9, 10.2);
    graph.edge(1, 2, 10, false);
    graph.edge(0, 4, 40, true);
    graph.edge(4, 3, 40, true);
    GraphHopper instance = new GraphHopper().setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
    // 3 -> 0
    GHResponse rsp = instance.route(new GHRequest(42, 10.4, 42, 10));
    assertFalse(rsp.hasErrors());
    PathWrapper arsp = rsp.getBest();
    assertEquals(80, arsp.getDistance(), 1e-6);
    PointList points = arsp.getPoints();
    assertEquals(42, points.getLatitude(0), 1e-5);
    assertEquals(10.4, points.getLongitude(0), 1e-5);
    assertEquals(41.9, points.getLatitude(1), 1e-5);
    assertEquals(10.2, points.getLongitude(1), 1e-5);
    assertEquals(3, points.getSize());
    instance.close();
}
Also used : PointList(com.graphhopper.util.PointList) NodeAccess(com.graphhopper.storage.NodeAccess) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 14 with PointList

use of com.graphhopper.util.PointList in project graphhopper by graphhopper.

the class WebHelperTest method testBoth.

@Test
public void testBoth() throws Exception {
    PointList list = Helper.createPointList(38.5, -120.2, 43.252, -126.453, 40.7, -120.95, 50.3139, 10.61279, 50.04303, 9.49768);
    String str = WebHelper.encodePolyline(list);
    assertEquals(list, WebHelper.decodePolyline(str, list.getSize(), false));
    list = Helper.createPointList(38.5, -120.2, 43.252, -126.453, 40.7, -120.95, 40.70001, -120.95001);
    str = WebHelper.encodePolyline(list);
    assertEquals(list, WebHelper.decodePolyline(str, list.getSize(), false));
}
Also used : PointList(com.graphhopper.util.PointList) Test(org.junit.Test)

Example 15 with PointList

use of com.graphhopper.util.PointList 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

PointList (com.graphhopper.util.PointList)22 Test (org.junit.Test)7 GHPoint (com.graphhopper.util.shapes.GHPoint)6 NodeAccess (com.graphhopper.storage.NodeAccess)5 ArrayList (java.util.ArrayList)3 PathWrapper (com.graphhopper.PathWrapper)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 BBox (com.graphhopper.util.shapes.BBox)2 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Agency (com.conveyal.gtfs.model.Agency)1 Fare (com.conveyal.gtfs.model.Fare)1 StopTime (com.conveyal.gtfs.model.StopTime)1 Trip (com.conveyal.gtfs.model.Trip)1 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1 NO_DATA (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.NO_DATA)1 SKIPPED (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED)1