Search in sources :

Example 1 with GHRequest

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

the class GraphHopperWebTest method testCreateURL.

@Test
public void testCreateURL() throws Exception {
    Downloader downloader = new Downloader("GraphHopper Test") {

        @Override
        public String downloadAsString(String url, boolean readErrorStreamNoException) throws IOException {
            assertFalse(url.contains("xy"));
            assertFalse(url.contains("algo1"));
            assertTrue(url.contains("alternative_route.max_paths=4"));
            assertEquals("https://graphhopper.com/api/1/route?point=52.0,13.0&point=52.0,14.0&&type=json&instructions=true&points_encoded=true&calc_points=true&algorithm=&locale=en_US&elevation=false&key=blup&alternative_route.max_paths=4", url);
            return Helper.isToString(getClass().getResourceAsStream("test_encoded.json"));
        }
    };
    GraphHopperWeb instance = new GraphHopperWeb();
    instance.setKey("blup");
    instance.setDownloader(downloader);
    GHRequest req = new GHRequest(52, 13, 52, 14);
    // should be ignored, use GraphHopperWeb or GHRequest directly instead
    req.getHints().put("key", "xy");
    req.getHints().put("algorithm", "algo1");
    req.getHints().put("alternative_route.max_paths", "4");
    instance.route(req);
}
Also used : GHRequest(com.graphhopper.GHRequest) Downloader(com.graphhopper.util.Downloader) Test(org.junit.Test)

Example 2 with GHRequest

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

the class GraphHopperWebTest method testReadEncoded.

// see also GraphHopperServletIT.testGraphHopperWeb for real routes against local jetty service    
@Test
public void testReadEncoded() throws Exception {
    Downloader downloader = new Downloader("GraphHopper Test") {

        @Override
        public InputStream fetch(HttpURLConnection conn, boolean readErrorStreamNoException) throws IOException {
            return getClass().getResourceAsStream("test_encoded.json");
        }
    };
    GraphHopperWeb instance = new GraphHopperWeb();
    instance.setDownloader(downloader);
    GHResponse rsp = instance.route(new GHRequest(52.47379, 13.362808, 52.4736925, 13.3904394));
    PathWrapper arsp = rsp.getBest();
    assertEquals(2138.3, arsp.getDistance(), 1e-1);
    assertEquals(17, arsp.getPoints().getSize());
    assertEquals(5, arsp.getInstructions().getSize());
    assertEquals("(0,Geradeaus auf A 100,1268.519329705091,65237)", arsp.getInstructions().get(0).toString());
    assertEquals(11, arsp.getInstructions().get(0).getPoints().size());
    assertEquals(43.73595, arsp.getWaypoints().getLat(0), 1e-4);
    assertEquals(7.42015, arsp.getWaypoints().getLon(0), 1e-4);
    assertEquals(43.73761, arsp.getWaypoints().getLat(1), 1e-4);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) Downloader(com.graphhopper.util.Downloader) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 3 with GHRequest

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

the class GraphHopperOSMTest method testLoadingWithDifferentCHConfig_issue471.

@Test
public void testLoadingWithDifferentCHConfig_issue471() {
    // with CH should not be loadable without CH configured
    GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
    try {
        gh.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.ch.weightings:"));
    }
    Helper.removeDir(new File(ghLoc));
    // without CH should not be loadable with CH enabled
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car"));
    try {
        gh.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.ch.weightings:"));
    }
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with GHRequest

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

the class GraphHopperOSMTest method testLoadOSMNoCH.

@Test
public void testLoadOSMNoCH() {
    GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
    GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
    assertTrue(gh.load(ghLoc));
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm).init(new CmdArgs().put("graph.flag_encoders", "car").put(Parameters.CH.PREPARE + "weightings", "no"));
    assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
    gh.close();
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 5 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)

Aggregations

GHRequest (com.graphhopper.GHRequest)106 GHResponse (com.graphhopper.GHResponse)86 GHPoint (com.graphhopper.util.shapes.GHPoint)59 Test (org.junit.Test)35 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)22 ResponsePath (com.graphhopper.ResponsePath)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 PathWrapper (com.graphhopper.PathWrapper)8 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 LMProfile (com.graphhopper.config.LMProfile)4