Search in sources :

Example 16 with GHRequest

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

the class GraphHopperWebIT method testPathDetails.

@Test
public void testPathDetails() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    req.getPathDetails().add("average_speed");
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    PathWrapper alt = res.getBest();
    assertEquals(1, alt.getPathDetails().size());
    List<PathDetail> details = alt.getPathDetails().get("average_speed");
    assertFalse(details.isEmpty());
    assertTrue((Double) details.get(0).getValue() > 20);
    assertTrue((Double) details.get(0).getValue() < 70);
}
Also used : PathWrapper(com.graphhopper.PathWrapper) PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 17 with GHRequest

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

the class GraphHopperWebIT method testOutOfBoundsException.

@Test
public void testOutOfBoundsException() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(-400.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 PointOutOfBoundsException);
}
Also used : GHRequest(com.graphhopper.GHRequest) PointOutOfBoundsException(com.graphhopper.util.exceptions.PointOutOfBoundsException) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 18 with GHRequest

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

the class GraphHopperWebIT method testCreateGPXFromInstructionList.

@Test
public void testCreateGPXFromInstructionList() {
    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 ghResponse = gh.route(req);
    String gpx = ghResponse.getBest().getInstructions().createGPX();
    assertTrue(gpx.contains("<gpx"));
    assertTrue(gpx.contains("<rtept lat="));
    assertTrue(gpx.contains("<trk><name>"));
    assertTrue(gpx.endsWith("</gpx>"));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 19 with GHRequest

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

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement3.

@Test
public void testGetPathsDirectionEnforcement3() {
    instance = createSquareGraphInstance(false);
    // Start in middle of edge 4-5
    GHPoint start = new GHPoint(0.0015, 0.002);
    // End at middle of edge 2-3
    GHPoint end = new GHPoint(0.002, 0.0005);
    // Via Point betweeen 8-7
    GHPoint via = new GHPoint(0.0005, 0.001);
    GHRequest req = new GHRequest().addPoint(start).addPoint(via, 0.).addPoint(end);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertEquals(IntArrayList.from(9, 5, 6, 7, 11), paths.get(0).calcNodes());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 20 with GHRequest

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

the class GraphHopperOSMTest method testFootAndCar.

@Test
public void testFootAndCar() {
    // now all ways are imported
    instance = new GraphHopperOSM().setStoreOnFlush(false).setEncodingManager(new EncodingManager("car,foot")).setCHEnabled(false).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm3);
    instance.importOrLoad();
    assertEquals(5, instance.getGraphHopperStorage().getNodes());
    assertEquals(8, instance.getGraphHopperStorage().getAllEdges().getMaxId());
    // A to D
    GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setVehicle("car"));
    assertFalse(grsp.hasErrors());
    PathWrapper rsp = grsp.getBest();
    assertEquals(3, rsp.getPoints().getSize());
    // => found A and D
    assertEquals(50, rsp.getPoints().getLongitude(0), 1e-3);
    assertEquals(11.1, rsp.getPoints().getLatitude(0), 1e-3);
    assertEquals(51, rsp.getPoints().getLongitude(2), 1e-3);
    assertEquals(11.3, rsp.getPoints().getLatitude(2), 1e-3);
    // A to D not allowed for foot. But the location index will choose a node close to D accessible to FOOT
    grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setVehicle("foot"));
    assertFalse(grsp.hasErrors());
    rsp = grsp.getBest();
    assertEquals(2, rsp.getPoints().getSize());
    // => found a point on edge A-B
    assertEquals(11.680, rsp.getPoints().getLatitude(1), 1e-3);
    assertEquals(50.644, rsp.getPoints().getLongitude(1), 1e-3);
    // A to E only for foot
    grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setVehicle("foot"));
    assertFalse(grsp.hasErrors());
    rsp = grsp.getBest();
    assertEquals(2, rsp.getPoints().size());
    // A D E for car
    grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setVehicle("car"));
    assertFalse(grsp.hasErrors());
    rsp = grsp.getBest();
    assertEquals(3, rsp.getPoints().getSize());
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) 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