Search in sources :

Example 61 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GraphHopperIT method checkMultiVehiclesWithCH.

private void checkMultiVehiclesWithCH(GraphHopper tmpHopper) {
    String str = tmpHopper.getEncodingManager().toString();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setVehicle("car"));
    PathWrapper arsp = rsp.getBest();
    assertFalse("car routing for " + str + " should not have errors:" + rsp.getErrors(), rsp.hasErrors());
    assertEquals(207, arsp.getTime() / 1000f, 1);
    assertEquals(2838, arsp.getDistance(), 1);
    rsp = tmpHopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setVehicle("bike"));
    arsp = rsp.getBest();
    assertFalse("bike routing for " + str + " should not have errors:" + rsp.getErrors(), rsp.hasErrors());
    assertEquals(494, arsp.getTime() / 1000f, 1);
    assertEquals(2192, arsp.getDistance(), 1);
    rsp = tmpHopper.route(new GHRequest(43.73005, 7.415707, 43.741522, 7.42826).setVehicle("foot"));
    assertTrue("only bike and car were imported. foot request should fail", rsp.hasErrors());
    GHRequest req = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854), 0.).addPoint(new GHPoint(43.744445, 7.429483), 190.).setVehicle("bike").setWeighting("fastest");
    rsp = hopper.route(req);
    assertTrue("heading not allowed for CH enabled graph", rsp.hasErrors());
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 62 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GraphHopperIT method testMonacoNonChMaxWaypointDistanceMultiplePoints.

@Test
public void testMonacoNonChMaxWaypointDistanceMultiplePoints() {
    GHPoint from = new GHPoint(43.741069, 7.426854);
    GHPoint via = new GHPoint(43.744445, 7.429483);
    GHPoint to = new GHPoint(43.727697, 7.419199);
    GHRequest req = new GHRequest().addPoint(from).addPoint(via).addPoint(to).setVehicle(vehicle).setWeighting("fastest");
    // Fail since points are too far
    hopper.setNonChMaxWaypointDistance(1000);
    GHResponse rsp = hopper.route(req);
    assertTrue(rsp.hasErrors());
    PointDistanceExceededException exception = (PointDistanceExceededException) rsp.getErrors().get(0);
    assertEquals(2, exception.getDetails().get("to"));
    // Suceed since points are not far anymore
    hopper.setNonChMaxWaypointDistance(Integer.MAX_VALUE);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors());
}
Also used : PointDistanceExceededException(com.graphhopper.util.exceptions.PointDistanceExceededException) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 63 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testVia.

@Test
public void testVia() {
    instance = new GraphHopperOSM().setStoreOnFlush(true).init(new CmdArgs().put("datareader.file", testOsm3).put("prepare.min_network_size", "1").put("graph.flag_encoders", "car")).setGraphHopperLocation(ghLoc);
    instance.importOrLoad();
    // A -> B -> C
    GHPoint first = new GHPoint(11.1, 50);
    GHPoint second = new GHPoint(12, 51);
    GHPoint third = new GHPoint(11.2, 51.9);
    GHResponse rsp12 = instance.route(new GHRequest().addPoint(first).addPoint(second));
    assertFalse("should find 1->2", rsp12.hasErrors());
    assertEquals(147930.5, rsp12.getBest().getDistance(), .1);
    GHResponse rsp23 = instance.route(new GHRequest().addPoint(second).addPoint(third));
    assertFalse("should find 2->3", rsp23.hasErrors());
    assertEquals(176608.9, rsp23.getBest().getDistance(), .1);
    GHResponse grsp = instance.route(new GHRequest().addPoint(first).addPoint(second).addPoint(third));
    assertFalse("should find 1->2->3", grsp.hasErrors());
    PathWrapper rsp = grsp.getBest();
    assertEquals(rsp12.getBest().getDistance() + rsp23.getBest().getDistance(), rsp.getDistance(), 1e-6);
    assertEquals(5, rsp.getPoints().getSize());
    assertEquals(5, rsp.getInstructions().size());
    assertEquals(Instruction.REACHED_VIA, rsp.getInstructions().get(1).getSign());
}
Also used : PathWrapper(com.graphhopper.PathWrapper) CmdArgs(com.graphhopper.util.CmdArgs) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 64 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class LandmarkStorageTest method testWithBorderBlocking.

@Test
public void testWithBorderBlocking() {
    AbstractRoutingAlgorithmTester.initBiGraph(ghStorage);
    LandmarkStorage storage = new LandmarkStorage(ghStorage, new RAMDirectory(), 2, new FastestWeighting(encoder), TraversalMode.NODE_BASED);
    final SpatialRule ruleRight = new DefaultSpatialRule() {

        @Override
        public String getId() {
            return "right";
        }
    };
    final SpatialRule ruleLeft = new DefaultSpatialRule() {

        @Override
        public String getId() {
            return "left";
        }
    };
    final SpatialRuleLookup lookup = new SpatialRuleLookup() {

        @Override
        public SpatialRule lookupRule(double lat, double lon) {
            if (lon > 0.00105)
                return ruleRight;
            return ruleLeft;
        }

        @Override
        public SpatialRule lookupRule(GHPoint point) {
            return lookupRule(point.lat, point.lon);
        }

        @Override
        public void addRule(SpatialRule rule) {
        }

        @Override
        public int getSpatialId(SpatialRule rule) {
            throw new IllegalStateException();
        }

        @Override
        public BBox getBounds() {
            throw new IllegalStateException();
        }

        @Override
        public int size() {
            return 2;
        }
    };
    storage.setSpatialRuleLookup(lookup);
    storage.setMinimumNodes(2);
    storage.createLandmarks();
    assertEquals(3, storage.getSubnetworksWithLandmarks());
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) SpatialRule(com.graphhopper.routing.util.spatialrules.SpatialRule) DefaultSpatialRule(com.graphhopper.routing.util.spatialrules.countries.DefaultSpatialRule) DefaultSpatialRule(com.graphhopper.routing.util.spatialrules.countries.DefaultSpatialRule) SpatialRuleLookup(com.graphhopper.routing.util.spatialrules.SpatialRuleLookup) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 65 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class QueryGraphTest method testInternalAPIOriginalTraversalKey.

@Test
public void testInternalAPIOriginalTraversalKey() {
    initGraph(g);
    EdgeExplorer explorer = g.createEdgeExplorer();
    QueryGraph queryGraph = new QueryGraph(g);
    EdgeIterator iter = explorer.setBaseNode(1);
    assertTrue(iter.next());
    int origEdgeId = iter.getEdge();
    QueryResult res = createLocationResult(2, 1.5, iter, 1, PILLAR);
    queryGraph.lookup(Arrays.asList(res));
    assertEquals(new GHPoint(1.5, 1.5), res.getSnappedPoint());
    assertEquals(3, res.getClosestNode());
    EdgeExplorer qGraphExplorer = queryGraph.createEdgeExplorer();
    iter = qGraphExplorer.setBaseNode(3);
    assertTrue(iter.next());
    assertEquals(0, iter.getAdjNode());
    assertEquals(GHUtility.createEdgeKey(1, 0, origEdgeId, false), ((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), 0)).getOriginalTraversalKey());
    assertTrue(iter.next());
    assertEquals(1, iter.getAdjNode());
    assertEquals(GHUtility.createEdgeKey(0, 1, origEdgeId, false), ((VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(iter.getEdge(), 1)).getOriginalTraversalKey());
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

GHPoint (com.graphhopper.util.shapes.GHPoint)69 Test (org.junit.Test)34 QueryResult (com.graphhopper.storage.index.QueryResult)15 GHRequest (com.graphhopper.GHRequest)10 GHResponse (com.graphhopper.GHResponse)10 PathWrapper (com.graphhopper.PathWrapper)6 DistanceCalcEarth (com.graphhopper.util.DistanceCalcEarth)5 PointList (com.graphhopper.util.PointList)3 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)3 BBox (com.graphhopper.util.shapes.BBox)3 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)3 Random (java.util.Random)3 JSONObject (org.json.JSONObject)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 SpatialRule (com.graphhopper.routing.util.spatialrules.SpatialRule)2 Graph (com.graphhopper.storage.Graph)2 VLongStorage (com.graphhopper.storage.VLongStorage)2 PointDistanceExceededException (com.graphhopper.util.exceptions.PointDistanceExceededException)2