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());
}
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"));
}
}
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));
}
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());
}
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));
}
Aggregations