Search in sources :

Example 1 with RAMDirectory

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

the class EncodingManager method create.

/**
     * Create the EncodingManager from the provided GraphHopper location. Throws an
     * IllegalStateException if it fails. Used if no EncodingManager specified on load.
     */
public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) {
    Directory dir = new RAMDirectory(ghLoc, true);
    StorableProperties properties = new StorableProperties(dir);
    if (!properties.loadExisting())
        throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation());
    // check encoding for compatibility
    properties.checkVersions(false);
    String acceptStr = properties.get("graph.flag_encoders");
    if (acceptStr.isEmpty())
        throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation());
    int bytesForFlags = 4;
    if ("8".equals(properties.get("graph.bytes_for_flags")))
        bytesForFlags = 8;
    return new EncodingManager(factory, acceptStr, bytesForFlags);
}
Also used : StorableProperties(com.graphhopper.storage.StorableProperties) RAMDirectory(com.graphhopper.storage.RAMDirectory) RAMDirectory(com.graphhopper.storage.RAMDirectory) Directory(com.graphhopper.storage.Directory)

Example 2 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;
    HeightTile instance = new HeightTile(0, 0, width, 1e-6, 10);
    DataAccess heights = new RAMDirectory().find("tmp");
    heights.create(2 * 10 * 10);
    instance.setHeights(heights);
    init(heights, 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(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 3 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, 1e-6, 10);
    DataAccess heights = new RAMDirectory().find("tmp");
    heights.create(2 * 10 * 10);
    instance.setHeights(heights);
    init(heights, 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 4 with RAMDirectory

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

the class OSMIDMapTest method testBinSearch.

@Test
public void testBinSearch() {
    DataAccess da = new RAMDirectory().find("");
    da.create(100);
    da.setInt(0 * 4, 1);
    da.setInt(1 * 4, 0);
    da.setInt(2 * 4, 5);
    da.setInt(3 * 4, 0);
    da.setInt(4 * 4, 100);
    da.setInt(5 * 4, 0);
    da.setInt(6 * 4, 300);
    da.setInt(7 * 4, 0);
    da.setInt(8 * 4, 333);
    da.setInt(9 * 4, 0);
    assertEquals(2, OSMIDMap.binarySearch(da, 0, 5, 100));
    assertEquals(3, OSMIDMap.binarySearch(da, 0, 5, 300));
    assertEquals(~3, OSMIDMap.binarySearch(da, 0, 5, 200));
    assertEquals(0, OSMIDMap.binarySearch(da, 0, 5, 1));
    assertEquals(1, OSMIDMap.binarySearch(da, 0, 5, 5));
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) DataAccess(com.graphhopper.storage.DataAccess) Test(org.junit.Test)

Example 5 with RAMDirectory

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

the class OSMIDMapTest method testGetLong.

@Test
public void testGetLong() {
    OSMIDMap map = new OSMIDMap(new RAMDirectory());
    map.put(12, 0);
    map.put(Long.MAX_VALUE / 10, 1);
    map.put(Long.MAX_VALUE / 9, 2);
    map.put(Long.MAX_VALUE / 7, 3);
    assertEquals(1, map.get(Long.MAX_VALUE / 10));
    assertEquals(3, map.get(Long.MAX_VALUE / 7));
    assertEquals(-1, map.get(13));
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Aggregations

RAMDirectory (com.graphhopper.storage.RAMDirectory)22 Test (org.junit.Test)16 Graph (com.graphhopper.storage.Graph)5 DataAccess (com.graphhopper.storage.DataAccess)4 NodeAccess (com.graphhopper.storage.NodeAccess)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Directory (com.graphhopper.storage.Directory)2 GraphExtension (com.graphhopper.storage.GraphExtension)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 GHRequest (com.graphhopper.GHRequest)1 GHResponse (com.graphhopper.GHResponse)1 JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1