Search in sources :

Example 16 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class HeightTileTest method testGetHeight.

@Test
public void testGetHeight() {
    // data access has same coordinate system as graphical or UI systems have (or the original DEM data has).
    // But HeightTile has lat,lon system ('mathematically')
    int width = 10;
    int height = 20;
    HeightTile instance = new HeightTile(0, 0, width, height, 1e-6, 10, 20);
    DataAccess heights = new RAMDirectory().find("tmp");
    heights.create(2 * width * height);
    instance.setHeights(heights);
    init(heights, width, height, 1);
    // x,y=1,7
    heights.setShort(2 * (17 * width + 1), (short) 70);
    // x,y=2,9
    heights.setShort(2 * (19 * width + 2), (short) 90);
    assertEquals(1, instance.getHeight(5, 5), 1e-3);
    assertEquals(70, instance.getHeight(2.5, 1.5), 1e-3);
    // edge cases for one tile with the boundaries [min,min+degree/width) for lat and lon
    assertEquals(1, instance.getHeight(3, 2), 1e-3);
    assertEquals(70, instance.getHeight(2, 1), 1e-3);
    // edge cases for the whole object
    assertEquals(1, instance.getHeight(+1.0, 2), 1e-3);
    assertEquals(90, instance.getHeight(0.5, 2.5), 1e-3);
    assertEquals(90, instance.getHeight(0.0, 2.5), 1e-3);
    assertEquals(1, instance.getHeight(+0.0, 3), 1e-3);
    assertEquals(1, instance.getHeight(-0.5, 3.5), 1e-3);
    assertEquals(1, instance.getHeight(-0.5, 3.0), 1e-3);
    // fall back to "2,9" if within its boundaries
    assertEquals(90, instance.getHeight(-0.5, 2.5), 1e-3);
    assertEquals(1, instance.getHeight(0, 0), 1e-3);
    assertEquals(1, instance.getHeight(9, 10), 1e-3);
    assertEquals(1, instance.getHeight(10, 9), 1e-3);
    assertEquals(1, instance.getHeight(10, 10), 1e-3);
    // no error
    assertEquals(1, instance.getHeight(10.5, 5), 1e-3);
    assertEquals(1, instance.getHeight(-0.5, 5), 1e-3);
    assertEquals(1, instance.getHeight(1, -0.5), 1e-3);
    assertEquals(1, instance.getHeight(1, 10.5), 1e-3);
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) DataAccess(com.graphhopper.storage.DataAccess) Test(org.junit.Test)

Example 17 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class HeightTileTest method testGetHeightForNegativeTile.

@Test
public void testGetHeightForNegativeTile() {
    int width = 10;
    HeightTile instance = new HeightTile(-20, -20, width, width, 1e-6, 10, 10);
    DataAccess heights = new RAMDirectory().find("tmp");
    heights.create(2 * 10 * 10);
    instance.setHeights(heights);
    init(heights, width, width, 1);
    // x,y=1,7
    heights.setShort(2 * (7 * width + 1), (short) 70);
    // x,y=2,9
    heights.setShort(2 * (9 * width + 2), (short) 90);
    assertEquals(1, instance.getHeight(-15, -15), 1e-3);
    assertEquals(70, instance.getHeight(-17.5, -18.5), 1e-3);
    // edge cases for one tile with the boundaries [min,min+degree/width) for lat and lon
    assertEquals(1, instance.getHeight(-17, -18), 1e-3);
    assertEquals(70, instance.getHeight(-18, -19), 1e-3);
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) DataAccess(com.graphhopper.storage.DataAccess) Test(org.junit.Test)

Example 18 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class LocationIndexTreeTest method createTestGraph.

// 0------\
// /|       \
// |1----3-\|
// |____/   4
// 2-------/
Graph createTestGraph(EncodingManager em) {
    Graph graph = createGHStorage(new RAMDirectory(), em, false);
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 0.5, -0.5);
    na.setNode(1, -0.5, -0.5);
    na.setNode(2, -1, -1);
    na.setNode(3, -0.4, 0.9);
    na.setNode(4, -0.6, 1.6);
    graph.edge(0, 1, 1, true);
    graph.edge(0, 2, 1, true);
    graph.edge(0, 4, 1, true);
    graph.edge(1, 3, 1, true);
    graph.edge(2, 3, 1, true);
    graph.edge(2, 4, 1, true);
    graph.edge(3, 4, 1, true);
    return graph;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) RAMDirectory(com.graphhopper.storage.RAMDirectory)

Example 19 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class LMAlgoFactoryDecoratorTest method addWeighting.

@Test
public void addWeighting() {
    LMAlgoFactoryDecorator dec = new LMAlgoFactoryDecorator().setEnabled(true);
    dec.addWeighting("fastest");
    assertEquals(Arrays.asList("fastest"), dec.getWeightingsAsStrings());
    // special parameters like the maximum weight
    dec = new LMAlgoFactoryDecorator().setEnabled(true);
    dec.addWeighting("fastest|maximum=65000");
    dec.addWeighting("shortest|maximum=20000");
    assertEquals(Arrays.asList("fastest", "shortest"), dec.getWeightingsAsStrings());
    FlagEncoder car = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(car);
    dec.addWeighting(new FastestWeighting(car)).addWeighting(new ShortestWeighting(car));
    dec.createPreparations(new GraphHopperStorage(new RAMDirectory(), em, false, new GraphExtension.NoOpExtension()), null);
    assertEquals(1, dec.getPreparations().get(0).getLandmarkStorage().getFactor(), .1);
    assertEquals(0.3, dec.getPreparations().get(1).getLandmarkStorage().getFactor(), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 20 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class HeightTileTest method testCalcMean.

@Test
public void testCalcMean() {
    int width = 10;
    HeightTile instance = new HeightTile(0, 0, width, width, 1e-6, 10, 10).setCalcMean(true);
    DataAccess heights = new RAMDirectory().find("tmp");
    heights.create(2 * 10 * 10);
    instance.setHeights(heights);
    init(heights, width, width, 1);
    // x,y=0,9
    heights.setShort(2 * (9 * width + 0), (short) 10);
    // x,y=1,7
    heights.setShort(2 * (7 * width + 1), (short) 70);
    // x,y=2,8
    heights.setShort(2 * (8 * width + 2), (short) 90);
    assertEquals((70 + 4) / 5d, instance.getHeight(2, 1), 1e-3);
    assertEquals((70 + 90 + 3) / 5d, instance.getHeight(2.5, 2.5), 1e-3);
    assertEquals((90 + 3) / 4d, instance.getHeight(-0.5, 2.5), 1e-3);
    assertEquals((10 + 2) / 3d, instance.getHeight(-0.5, -0.5), 1e-3);
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) DataAccess(com.graphhopper.storage.DataAccess) Test(org.junit.Test)

Aggregations

RAMDirectory (com.graphhopper.storage.RAMDirectory)25 Test (org.junit.Test)18 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 DataAccess (com.graphhopper.storage.DataAccess)4 Directory (com.graphhopper.storage.Directory)4 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 GraphExtension (com.graphhopper.storage.GraphExtension)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 ReaderWay (com.graphhopper.reader.ReaderWay)1