Search in sources :

Example 26 with GraphHopper

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

the class GraphHopperOSMTest method testGetMultipleWeightingsForCH.

@Test
public void testGetMultipleWeightingsForCH() {
    EncodingManager em = new EncodingManager(Arrays.asList(new CarFlagEncoder()), 8);
    GraphHopper tmpGH = new GraphHopperOSM().setStoreOnFlush(false).setEncodingManager(em);
    tmpGH.getCHFactoryDecorator().setWeightingsAsStrings("fastest", "shortest");
    assertEquals(2, tmpGH.getCHFactoryDecorator().getWeightingsAsStrings().size());
}
Also used : GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 27 with GraphHopper

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

the class GraphHopperOSMTest method testFailsForWrongConfig.

@Test
public void testFailsForWrongConfig() throws IOException {
    instance = new GraphHopperOSM().init(new CmdArgs().put("datareader.file", testOsm3).put("datareader.dataaccess", "RAM").put("graph.flag_encoders", "foot,car").put(Parameters.CH.PREPARE + "weightings", "no")).setGraphHopperLocation(ghLoc);
    instance.importOrLoad();
    assertEquals(5, instance.getGraphHopperStorage().getNodes());
    instance.close();
    // different config (flagEncoder list)
    try {
        GraphHopper tmpGH = new GraphHopperOSM().init(new CmdArgs().put("datareader.file", testOsm3).put("datareader.dataaccess", "RAM").put("graph.flag_encoders", "foot").put(Parameters.CH.PREPARE + "weightings", "no")).setDataReaderFile(testOsm3);
        tmpGH.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Encoding does not match"));
    }
    // different bytesForFlags should fail to load
    instance = new GraphHopperOSM().init(new CmdArgs().put("datareader.file", testOsm3).put("datareader.dataaccess", "RAM").put("graph.flag_encoders", "foot,car").put("graph.bytes_for_flags", 8).put(Parameters.CH.PREPARE + "weightings", "no")).setDataReaderFile(testOsm3);
    try {
        instance.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.bytes_for_flags (8) is not equal to loaded 4"));
    }
    // different order is no longer okay, see #350
    try {
        GraphHopper tmpGH = new GraphHopperOSM().init(new CmdArgs().put("datareader.file", testOsm3).put("datareader.dataaccess", "RAM").put(Parameters.CH.PREPARE + "weightings", "no").put("graph.flag_encoders", "car,foot")).setDataReaderFile(testOsm3);
        tmpGH.load(ghLoc);
        assertTrue(false);
    } catch (Exception ex) {
        assertTrue(ex.getMessage(), ex.getMessage().startsWith("Encoding does not match"));
    }
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) GraphHopper(com.graphhopper.GraphHopper) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with GraphHopper

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

the class OSMReaderTest method testReadEleFromDataProvider.

@Test
public void testReadEleFromDataProvider() {
    GraphHopper hopper = new GraphHopperFacade("test-osm5.xml");
    // get N10E046.hgt.zip
    ElevationProvider provider = new SRTMProvider();
    provider.setCacheDir(new File(GraphHopperIT.DIR));
    hopper.setElevationProvider(provider);
    hopper.importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 49.501);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 49.5011);
    int n50 = AbstractGraphStorageTester.getIdOf(graph, 49.5001);
    EdgeIteratorState edge = GHUtility.getEdge(graph, n50, n30);
    assertEquals(Helper.createPointList3D(49.5001, 11.501, 426, 49.5002, 11.5015, 441, 49.5011, 11.502, 410.0), edge.fetchWayGeometry(3));
    edge = GHUtility.getEdge(graph, n10, n50);
    assertEquals(Helper.createPointList3D(49.501, 11.5001, 383.0, 49.5001, 11.501, 426.0), edge.fetchWayGeometry(3));
}
Also used : ElevationProvider(com.graphhopper.reader.dem.ElevationProvider) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) GHPoint(com.graphhopper.util.shapes.GHPoint) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) Test(org.junit.Test)

Example 29 with GraphHopper

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

the class OSMReaderTest method testPreferredLanguage.

@Test
public void testPreferredLanguage() {
    GraphHopper hopper = new GraphHopperFacade(file1).setPreferredLanguage("de").importOrLoad();
    GraphHopperStorage graph = hopper.getGraphHopperStorage();
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    EdgeIterator iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertEquals("straße 123, B 122", iter.getName());
    hopper = new GraphHopperFacade(file1).setPreferredLanguage("el").importOrLoad();
    graph = hopper.getGraphHopperStorage();
    n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
    iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertTrue(iter.next());
    assertEquals("διαδρομή 666", iter.getName());
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 30 with GraphHopper

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

the class OSMReaderTest method testOneWay.

@Test
public void testOneWay() {
    GraphHopper hopper = new GraphHopperFacade(file2).importOrLoad();
    GraphHopperStorage graph = hopper.getGraphHopperStorage();
    assertEquals("2014-01-02T01:10:14Z", graph.getProperties().get("datareader.data.date"));
    int n20 = AbstractGraphStorageTester.getIdOf(graph, 52.0);
    int n22 = AbstractGraphStorageTester.getIdOf(graph, 52.133);
    int n23 = AbstractGraphStorageTester.getIdOf(graph, 52.144);
    int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
    int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
    assertEquals(1, GHUtility.count(carOutExplorer.setBaseNode(n10)));
    assertEquals(2, GHUtility.count(carOutExplorer.setBaseNode(n20)));
    assertEquals(0, GHUtility.count(carOutExplorer.setBaseNode(n30)));
    EdgeIterator iter = carOutExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertTrue(iter.next());
    assertEquals(n30, iter.getAdjNode());
    FlagEncoder encoder = carEncoder;
    iter = carAllExplorer.setBaseNode(n20);
    assertTrue(iter.next());
    assertEquals(n23, iter.getAdjNode());
    assertTrue(iter.isForward(encoder));
    assertFalse(iter.isBackward(encoder));
    assertTrue(iter.next());
    assertEquals(n22, iter.getAdjNode());
    assertFalse(iter.isForward(encoder));
    assertTrue(iter.isBackward(encoder));
    assertTrue(iter.next());
    assertFalse(iter.isForward(encoder));
    assertTrue(iter.isBackward(encoder));
    assertTrue(iter.next());
    assertEquals(n30, iter.getAdjNode());
    assertTrue(iter.isForward(encoder));
    assertFalse(iter.isBackward(encoder));
    assertTrue(iter.next());
    assertEquals(n10, iter.getAdjNode());
    assertFalse(iter.isForward(encoder));
    assertTrue(iter.isBackward(encoder));
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)37 Test (org.junit.Test)31 GHPoint (com.graphhopper.util.shapes.GHPoint)17 IOException (java.io.IOException)7 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)6 GHRequest (com.graphhopper.GHRequest)4 GHResponse (com.graphhopper.GHResponse)4 File (java.io.File)4 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CmdArgs (com.graphhopper.util.CmdArgs)3 ReaderNode (com.graphhopper.reader.ReaderNode)2 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)2 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)2 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 QueryResult (com.graphhopper.storage.index.QueryResult)2