Search in sources :

Example 56 with GHResponse

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

the class GraphHopperWebIT method doNotReadFinishInstruction.

@Test
public void doNotReadFinishInstruction() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.261434, 13.485718)).addPoint(new GHPoint(52.399067, 13.469238));
    req.getHints().put("turn_description", false);
    GHResponse res = gh.route(req);
    InstructionList instructions = res.getBest().getInstructions();
    String finishInstructionName = instructions.get(instructions.size() - 1).getName();
    assertEquals("", 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 57 with GHResponse

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

the class GraphHopperWebIT method testAlternativeRoute.

@Test
public void testAlternativeRoute() {
    // https://graphhopper.com/maps/?point=52.042989%2C10.373926&point=52.042289%2C10.384043&algorithm=alternative_route&ch.disable=true
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.042989, 10.373926)).addPoint(new GHPoint(52.042289, 10.384043));
    req.setAlgorithm("alternative_route");
    req.getHints().put("instructions", true);
    req.getHints().put("calc_points", true);
    req.getHints().put("ch.disable", true);
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    List<PathWrapper> paths = res.getAll();
    assertEquals(2, paths.size());
    PathWrapper path = paths.get(0);
    isBetween(5, 20, path.getPoints().size());
    isBetween(1000, 1100, path.getDistance());
    assertEquals("Wiesenstraße", path.getDescription().get(0));
    path = paths.get(1);
    isBetween(20, 30, path.getPoints().size());
    isBetween(800, 900, path.getDistance());
    assertEquals("Jacobistraße", path.getDescription().get(0));
}
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 58 with GHResponse

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

the class GraphHopperWebIT method testNoPoints.

@Test
public void testNoPoints() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    req.getHints().put("instructions", false);
    req.getHints().put("calc_points", false);
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    PathWrapper alt = res.getBest();
    assertEquals(0, alt.getPoints().size());
    isBetween(11000, 12000, 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 59 with GHResponse

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

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement6.

@Test
public void testGetPathsDirectionEnforcement6() {
    // Test if query results at tower nodes are ignored
    instance = createSquareGraphInstance(false);
    // QueryPoints directly on TowerNodes
    GHPoint start = new GHPoint(0, 0);
    GHPoint via = new GHPoint(0.002, 0.000);
    GHPoint end = new GHPoint(0.002, 0.002);
    GHRequest req = new GHRequest().addPoint(start, 90.).addPoint(via, 270.).addPoint(end, 270.);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertArrayEquals(new int[] { 0, 1, 2 }, paths.get(0).calcNodes().toArray());
    assertArrayEquals(new int[] { 2, 3, 4 }, paths.get(1).calcNodes().toArray());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 60 with GHResponse

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

the class GraphHopperOSMTest method testGetPathsDirectionEnforcement1.

@Test
public void testGetPathsDirectionEnforcement1() {
    // Test enforce start direction
    // Note: This Test does not pass for CH enabled
    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);
    GHRequest req = new GHRequest().addPoint(start, 180.).addPoint(end);
    GHResponse response = new GHResponse();
    List<Path> paths = instance.calcPaths(req, response);
    assertFalse(response.hasErrors());
    assertArrayEquals(new int[] { 9, 5, 8, 3, 10 }, paths.get(0).calcNodes().toArray());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Aggregations

GHResponse (com.graphhopper.GHResponse)100 GHRequest (com.graphhopper.GHRequest)86 GHPoint (com.graphhopper.util.shapes.GHPoint)52 Test (org.junit.Test)31 Test (org.junit.jupiter.api.Test)31 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ResponsePath (com.graphhopper.ResponsePath)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 PathWrapper (com.graphhopper.PathWrapper)9 GraphHopper (com.graphhopper.GraphHopper)7 InstructionList (com.graphhopper.util.InstructionList)7 PathDetail (com.graphhopper.util.details.PathDetail)7 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Profile (com.graphhopper.config.Profile)5 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)5