Search in sources :

Example 6 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method executeCHFootRoute.

private void executeCHFootRoute() {
    String tmpOsmFile = DIR + "/monaco.osm.gz";
    String tmpImportVehicles = "foot";
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(tmpImportVehicles));
    tmpHopper.getCHFactoryDecorator().setWeightingsAsStrings(weightCalcStr);
    tmpHopper.importOrLoad();
    // same query as in testMonacoWithInstructions
    GHResponse rsp = tmpHopper.route(new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setVehicle(vehicle));
    PathWrapper bestPath = rsp.getBest();
    // identify the number of counts to compare with none-CH foot route which had nearly 700 counts
    long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertNotEquals(sum, 0);
    assertTrue("Too many nodes visited " + sum, sum < 120);
    assertEquals(3437.6, bestPath.getDistance(), .1);
    assertEquals(89, bestPath.getPoints().getSize());
    tmpHopper.close();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 7 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method testNorthBayreuthDestination.

@Test
public void testNorthBayreuthDestination() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car,generic", 8));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setVehicle("car").setWeighting("fastest");
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(550, rsp.getBest().getDistance(), 1);
    req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setVehicle("generic").setWeighting("generic");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(550, rsp.getBest().getDistance(), 1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 8 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method testNorthBayreuthBlockeEdges.

@Test
public void testNorthBayreuthBlockeEdges() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("generic", 8));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(49.985272, 11.506151, 49.986107, 11.507202).setVehicle("generic").setWeighting("generic");
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(122, rsp.getBest().getDistance(), 1);
    // block point 49.985759,11.50687
    req.getHints().put(Routing.BLOCK_AREA, "49.985759,11.50687");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(365, rsp.getBest().getDistance(), 1);
    req = new GHRequest(49.975845, 11.522598, 50.026821, 11.497364).setVehicle("generic").setWeighting("generic");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(6684, rsp.getBest().getDistance(), 1);
    // block by area
    String someArea = "49.97986,11.472902,50.003946,11.534357";
    req.getHints().put(Routing.BLOCK_AREA, someArea);
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(12173, rsp.getBest().getDistance(), 1);
    // Add blocked point to above area, to increase detour        
    req.getHints().put(Routing.BLOCK_AREA, "50.017578,11.547527;" + someArea);
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(16674, rsp.getBest().getDistance(), 1);
    // block by edge IDs -> i.e. use small circular area
    req.getHints().put(Routing.BLOCK_AREA, "49.981599,11.517448,100");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(6879, rsp.getBest().getDistance(), 1);
    // block by edge IDs -> i.e. use small rectangular area
    req.getHints().put(Routing.BLOCK_AREA, "49.981875,11.515818,49.981088,11.519423");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(6879, rsp.getBest().getDistance(), 1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 9 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method testSRTMWithInstructions.

@Test
public void testSRTMWithInstructions() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(importVehicles));
    tmpHopper.setElevationProvider(new SRTMProvider().setCacheDir(new File(DIR)));
    tmpHopper.importOrLoad();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.730729, 7.421288, 43.727697, 7.419199).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
    PathWrapper arsp = rsp.getBest();
    assertEquals(1626.8, arsp.getDistance(), .1);
    assertEquals(60, arsp.getPoints().getSize());
    assertTrue(arsp.getPoints().is3D());
    InstructionList il = arsp.getInstructions();
    assertEquals(10, il.size());
    assertTrue(il.get(0).getPoints().is3D());
    String str = arsp.getPoints().toString();
    assertEquals("(43.73068455771767,7.421283689825812,62.0), (43.73067957305937,7.421382123709815,66.0), " + "(43.73109792316924,7.421546222751131,45.0), (43.73129908884985,7.421589994913116,45.0), " + "(43.731327028527716,7.421414533736137,45.0), (43.73125047381037,7.421366291225693,45.0), " + "(43.73125457162979,7.421274090288746,52.0), " + "(43.73128213877862,7.421115579183003,52.0), (43.731362232521825,7.421145381506057,52.0), " + "(43.731371359483255,7.421123216028286,52.0), (43.731485725897976,7.42117332118392,52.0), " + "(43.731575132867135,7.420868778695214,52.0), (43.73160605277731,7.420824820268709,52.0), " + "(43.7316401391843,7.420850152243305,52.0), (43.731674039326776,7.421050014072285,52.0)", str.substring(0, 662));
    assertEquals("(43.727778875703635,7.418772930326453,11.0), (43.72768239068275,7.419007064826944,11.0), " + "(43.727680946587874,7.419198768422206,11.0)", str.substring(str.length() - 132));
    assertEquals(84, arsp.getAscend(), 1e-1);
    assertEquals(135, arsp.getDescend(), 1e-1);
    List<GPXEntry> list = arsp.getInstructions().createGPXList();
    assertEquals(60, list.size());
    final long lastEntryMillis = list.get(list.size() - 1).getTime();
    assertEquals(new GPXEntry(43.73068455771767, 7.421283689825812, 62.0, 0), list.get(0));
    assertEquals(new GPXEntry(43.727680946587874, 7.4191987684222065, 11.0, lastEntryMillis), list.get(list.size() - 1));
    assertEquals(62, il.createGPXList().get(0).getElevation(), 1e-2);
    assertEquals(66, il.createGPXList().get(1).getElevation(), 1e-2);
    assertEquals(52, il.createGPXList().get(10).getElevation(), 1e-2);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) File(java.io.File)

Example 10 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method testTurnCostsOnOff.

@Test
public void testTurnCostsOnOff() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/moscow.osm.gz").setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car|turn_costs=true"));
    tmpHopper.importOrLoad();
    // with turn costs (default if none-CH and turn cost enabled)
    GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
    GHResponse rsp = tmpHopper.route(req);
    assertEquals(1044, rsp.getBest().getDistance(), 1);
    // without turn costs
    req.getHints().put(Routing.EDGE_BASED, "false");
    rsp = tmpHopper.route(req);
    assertEquals(400, rsp.getBest().getDistance(), 1);
    // with turn costs
    req.getHints().put(Routing.EDGE_BASED, "true");
    rsp = tmpHopper.route(req);
    assertEquals(1044, rsp.getBest().getDistance(), 1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Aggregations

GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)21 EncodingManager (com.graphhopper.routing.util.EncodingManager)14 File (java.io.File)7 GraphHopper (com.graphhopper.GraphHopper)6 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)4 IOException (java.io.IOException)3 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHJsonBuilder (com.graphhopper.json.GHJsonBuilder)1 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)1 DataReader (com.graphhopper.reader.DataReader)1 LandmarkStorage (com.graphhopper.routing.lm.LandmarkStorage)1 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)1 SpatialRuleLookup (com.graphhopper.routing.util.spatialrules.SpatialRuleLookup)1 SpatialRuleLookupBuilder (com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder)1 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)1 CHGraph (com.graphhopper.storage.CHGraph)1