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