Search in sources :

Example 11 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testSimpleRoute.

@Test
public void testSimpleRoute() {
    // https://graphhopper.com/maps/?point=49.6724%2C11.3494&point=49.655%2C11.418
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    req.getHints().put("elevation", false);
    req.getHints().put("instructions", true);
    req.getHints().put("calc_points", true);
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    PathWrapper alt = res.getBest();
    isBetween(200, 250, alt.getPoints().size());
    isBetween(11000, 12000, alt.getDistance());
    isBetween(310, 320, alt.getAscend());
    isBetween(235, 245, alt.getDescend());
    isBetween(1000, 1500, alt.getRouteWeight());
    // change vehicle
    res = gh.route(new GHRequest(49.6724, 11.3494, 49.6550, 11.4180).setVehicle("bike"));
    alt = res.getBest();
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    isBetween(9000, 9500, alt.getDistance());
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 12 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method readFinishInstruction.

@Test
public void readFinishInstruction() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.261434, 13.485718)).addPoint(new GHPoint(52.399067, 13.469238));
    GHResponse res = gh.route(req);
    InstructionList instructions = res.getBest().getInstructions();
    String finishInstructionName = instructions.get(instructions.size() - 1).getName();
    assertEquals("Arrive at destination", finishInstructionName);
}
Also used : InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 13 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testCannotFindPointException.

@Test
public void testCannotFindPointException() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(-4.214943, -130.078125)).addPoint(new GHPoint(39.909736, -91.054687));
    GHResponse res = gh.route(req);
    assertTrue("no erros found?", res.hasErrors());
    assertTrue(res.getErrors().get(0) instanceof PointNotFoundException);
}
Also used : PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 14 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testSimpleExport.

@Test
public void testSimpleExport() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    req.getHints().put("elevation", false);
    req.getHints().put("instructions", true);
    req.getHints().put("calc_points", true);
    req.getHints().put("type", "gpx");
    String res = gh.export(req);
    assertTrue(res.contains("<gpx"));
    assertTrue(res.contains("<rtept lat="));
    assertTrue(res.contains("<trk><name>GraphHopper Track</name><trkseg>"));
    assertTrue(res.endsWith("</gpx>"));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 15 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method readRoundabout.

@Test
public void readRoundabout() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.261434, 13.485718)).addPoint(new GHPoint(52.399067, 13.469238));
    GHResponse res = gh.route(req);
    int counter = 0;
    for (Instruction i : res.getBest().getInstructions()) {
        if (i instanceof RoundaboutInstruction) {
            counter++;
            RoundaboutInstruction ri = (RoundaboutInstruction) i;
            assertEquals("turn_angle was incorrect:" + ri.getTurnAngle(), -1.5, ri.getTurnAngle(), 0.1);
            // This route contains only one roundabout and no (via) point in a roundabout
            assertEquals("exited was incorrect:" + ri.isExited(), ri.isExited(), true);
        }
    }
    assertTrue("no roundabout in route?", counter > 0);
}
Also used : GHRequest(com.graphhopper.GHRequest) RoundaboutInstruction(com.graphhopper.util.RoundaboutInstruction) Instruction(com.graphhopper.util.Instruction) RoundaboutInstruction(com.graphhopper.util.RoundaboutInstruction) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

GHRequest (com.graphhopper.GHRequest)50 Test (org.junit.Test)43 GHResponse (com.graphhopper.GHResponse)42 GHPoint (com.graphhopper.util.shapes.GHPoint)26 PathWrapper (com.graphhopper.PathWrapper)13 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 GraphHopper (com.graphhopper.GraphHopper)4 CHGraph (com.graphhopper.storage.CHGraph)3 Graph (com.graphhopper.storage.Graph)3 NodeAccess (com.graphhopper.storage.NodeAccess)3 CmdArgs (com.graphhopper.util.CmdArgs)3 IOException (java.io.IOException)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 QueryResult (com.graphhopper.storage.index.QueryResult)2 Downloader (com.graphhopper.util.Downloader)2 InstructionList (com.graphhopper.util.InstructionList)2 PathDetail (com.graphhopper.util.details.PathDetail)2