Search in sources :

Example 1 with SRTMProvider

use of com.graphhopper.reader.dem.SRTMProvider 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 2 with SRTMProvider

use of com.graphhopper.reader.dem.SRTMProvider in project graphhopper by graphhopper.

the class GraphHopperIT method testSRTMWithTunnelInterpolation.

@Test
public void testSRTMWithTunnelInterpolation() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(genericImportVehicles, 8));
    tmpHopper.setElevationProvider(new SRTMProvider().setCacheDir(new File(DIR)));
    tmpHopper.importOrLoad();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.74056471749763, 7.4299266210693755, 43.73790260334179, 7.427984089259056).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
    PathWrapper arsp = rsp.getBest();
    // Without interpolation: 356.5
    assertEquals(351.4, arsp.getDistance(), .1);
    PointList pointList = arsp.getPoints();
    assertEquals(6, pointList.getSize());
    assertTrue(pointList.is3D());
    assertEquals(17, pointList.getEle(0), .1);
    assertEquals(19.04, pointList.getEle(1), .1);
    assertEquals(21.67, pointList.getEle(2), .1);
    assertEquals(25.03, pointList.getEle(3), .1);
    assertEquals(28.65, pointList.getEle(4), .1);
    assertEquals(31.32, pointList.getEle(5), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) File(java.io.File) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider)

Example 3 with SRTMProvider

use of com.graphhopper.reader.dem.SRTMProvider in project graphhopper by graphhopper.

the class GraphHopperIT method testSRTMWithoutTunnelInterpolation.

@Test
public void testSRTMWithoutTunnelInterpolation() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(importVehicles, 8));
    tmpHopper.setElevationProvider(new SRTMProvider().setCacheDir(new File(DIR)));
    tmpHopper.importOrLoad();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.74056471749763, 7.4299266210693755, 43.73790260334179, 7.427984089259056).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
    PathWrapper arsp = rsp.getBest();
    assertEquals(356.5, arsp.getDistance(), .1);
    PointList pointList = arsp.getPoints();
    assertEquals(6, pointList.getSize());
    assertTrue(pointList.is3D());
    assertEquals(20.0, pointList.getEle(0), .1);
    assertEquals(23.0, pointList.getEle(1), .1);
    assertEquals(23.0, pointList.getEle(2), .1);
    assertEquals(41.0, pointList.getEle(3), .1);
    assertEquals(19.0, pointList.getEle(4), .1);
    assertEquals(26.5, pointList.getEle(5), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) File(java.io.File) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider)

Example 4 with SRTMProvider

use of com.graphhopper.reader.dem.SRTMProvider in project graphhopper by graphhopper.

the class RoutingAlgorithmWithOSMIT method runAlgo.

/**
     * @param withCH if true also the CH and LM algorithms will be tested which need
     *               preparation and takes a bit longer
     */
Graph runAlgo(TestAlgoCollector testCollector, String osmFile, String graphFile, List<OneRun> forEveryAlgo, String importVehicles, boolean withCH, String vehicle, String weightStr, boolean is3D) {
    // for different weightings we need a different storage, otherwise we would need to remove the graph folder
    // everytime we come with a different weighting
    // graphFile += weightStr;
    AlgoHelperEntry algoEntry = null;
    OneRun tmpOneRun = null;
    try {
        Helper.removeDir(new File(graphFile));
        GraphHopper hopper = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setDataReaderFile(osmFile).setGraphHopperLocation(graphFile).setEncodingManager(new EncodingManager(importVehicles));
        // avoid that path.getDistance is too different to path.getPoint.calcDistance
        hopper.setWayPointMaxDistance(0);
        // always enable landmarks
        hopper.getLMFactoryDecorator().addWeighting(weightStr).setEnabled(true).setDisablingAllowed(true);
        if (withCH)
            hopper.getCHFactoryDecorator().addWeighting(weightStr).setEnabled(true).setDisablingAllowed(true);
        if (is3D)
            hopper.setElevationProvider(new SRTMProvider().setCacheDir(new File(DIR)));
        hopper.importOrLoad();
        TraversalMode tMode = importVehicles.contains("turn_costs=true") ? TraversalMode.EDGE_BASED_2DIR : TraversalMode.NODE_BASED;
        FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicle);
        HintsMap hints = new HintsMap().setWeighting(weightStr).setVehicle(vehicle);
        Collection<AlgoHelperEntry> prepares = RoutingAlgorithmIT.createAlgos(hopper, hints, tMode);
        EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder);
        for (AlgoHelperEntry entry : prepares) {
            algoEntry = entry;
            LocationIndex idx = entry.getIdx();
            for (OneRun oneRun : forEveryAlgo) {
                tmpOneRun = oneRun;
                List<QueryResult> list = oneRun.getList(idx, edgeFilter);
                testCollector.assertDistance(algoEntry, list, oneRun);
            }
        }
        return hopper.getGraphHopperStorage();
    } catch (Exception ex) {
        if (algoEntry == null)
            throw new RuntimeException("cannot handle file " + osmFile + ", " + ex.getMessage(), ex);
        throw new RuntimeException("cannot handle " + algoEntry.toString() + ", for " + tmpOneRun + ", file " + osmFile + ", " + ex.getMessage(), ex);
    } finally {
    // Helper.removeDir(new File(graphFile));
    }
}
Also used : AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) OneRun(com.graphhopper.routing.util.TestAlgoCollector.OneRun) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper) LocationIndex(com.graphhopper.storage.index.LocationIndex) IOException(java.io.IOException) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) QueryResult(com.graphhopper.storage.index.QueryResult) File(java.io.File)

Example 5 with SRTMProvider

use of com.graphhopper.reader.dem.SRTMProvider 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)

Aggregations

SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)5 File (java.io.File)5 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 GraphHopper (com.graphhopper.GraphHopper)2 ElevationProvider (com.graphhopper.reader.dem.ElevationProvider)1 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)1 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 QueryResult (com.graphhopper.storage.index.QueryResult)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 IOException (java.io.IOException)1 Test (org.junit.Test)1