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