use of com.graphhopper.util.DistanceCalcEarth in project graphhopper by graphhopper.
the class BBoxTest method testCreate.
@Test
public void testCreate() {
DistanceCalc c = new DistanceCalcEarth();
BBox b = c.createBBox(52, 10, 100000);
// The calclulated bounding box has no negative values (also for southern hemisphere and negative meridians)
// and the ordering is always the same (top to bottom and left to right)
assertEquals(52.8993, b.maxLat, 1e-4);
assertEquals(8.5393, b.minLon, 1e-4);
assertEquals(51.1007, b.minLat, 1e-4);
assertEquals(11.4607, b.maxLon, 1e-4);
}
use of com.graphhopper.util.DistanceCalcEarth in project graphhopper by graphhopper.
the class SpatialKeyAlgoTest method testBijection.
public void testBijection(int bits) {
SpatialKeyAlgo algo = new SpatialKeyAlgo(bits);
GHPoint coord11 = new GHPoint();
long key = algo.encode(1, 1);
algo.decode(key, coord11);
long resKey = algo.encode(coord11.lat, coord11.lon);
GHPoint coord2 = new GHPoint();
algo.decode(resKey, coord2);
assertEquals(key, resKey);
GHPoint coord = new GHPoint(50.022846, 9.2123575);
key = algo.encode(coord);
algo.decode(key, coord2);
assertEquals(key, algo.encode(coord2));
double dist = new DistanceCalcEarth().calcDist(coord.lat, coord.lon, coord2.lat, coord2.lon);
// and ensure small distance
assertTrue(dist + "", dist < 5);
long queriedKey = 246557819640268L;
long storedKey = 246557819640269L;
algo.decode(queriedKey, coord);
algo.decode(storedKey, coord2);
// 2. fix bijection precision problem
assertEquals(storedKey, algo.encode(coord2));
dist = new DistanceCalcEarth().calcDist(coord.lat, coord.lon, coord2.lat, coord2.lon);
// and ensure small distance
assertTrue(dist + "", dist < 5);
coord = new GHPoint(50.0606072, 9.6277542);
key = algo.encode(coord);
algo.decode(key, coord2);
assertEquals(key, algo.encode(coord2));
dist = new DistanceCalcEarth().calcDist(coord.lat, coord.lon, coord2.lat, coord2.lon);
// and ensure small distance
assertTrue(dist + "", dist < 5);
coord = new GHPoint(0.01, 0.01);
key = algo.encode(coord);
algo.decode(key, coord2);
assertEquals(key, algo.encode(coord2));
dist = new DistanceCalcEarth().calcDist(coord.lat, coord.lon, coord2.lat, coord2.lon);
// and ensure small distance
assertTrue(dist + "", dist < 5);
}
use of com.graphhopper.util.DistanceCalcEarth in project graphhopper by graphhopper.
the class SpatialKeyAlgoTest method testEncode3BytesPrecision.
@Test
public void testEncode3BytesPrecision() {
// 3 bytes => c / 1^12 = ~10km
int bits = 3 * 8;
SpatialKeyAlgo algo = new SpatialKeyAlgo(bits);
float lat = 24.235345f;
float lon = 47.234234f;
long val = algo.encode(lat, lon);
assertEquals("00000000" + "110011000000100101101011", BitUtil.BIG.toLastBitString(val, 32));
GHPoint fl = new GHPoint();
algo.decode(val, fl);
// normally 10km are expected here we have only 100meters ... (?)
assertEquals(lat, fl.lat, .1);
assertEquals(lon, fl.lon, .1);
double expectedDist = ((float) DistanceCalcEarth.C / (1 << bits / 2));
double d = new DistanceCalcEarth().calcDist(lat, lon, fl.lat, fl.lon);
assertTrue("Returned point shouldn't be more far away than " + expectedDist + " -> It was " + d, d < expectedDist);
}
use of com.graphhopper.util.DistanceCalcEarth in project graphhopper by graphhopper.
the class SpatialKeyAlgoTest method testEncode6BytesPrecision.
@Test
public void testEncode6BytesPrecision() {
int bits = 6 * 8;
SpatialKeyAlgo algo = new SpatialKeyAlgo(bits);
float lat = 24.235345f;
float lon = 47.234234f;
long val = algo.encode(lat, lon);
assertEquals("11001100000010010110101100111110" + "11100111" + "01000110", BitUtil.BIG.toLastBitString(val, bits));
GHPoint fl = new GHPoint();
algo.decode(val, fl);
assertEquals(lat, fl.lat, 1e-4);
assertEquals(lon, fl.lon, 1e-4);
double expectedDist = ((float) DistanceCalcEarth.C / (1 << bits / 2));
double d = new DistanceCalcEarth().calcDist(lat, lon, fl.lat, fl.lon);
assertTrue("Returned point shouldn't be more far away than " + expectedDist + " -> It was " + d, d < expectedDist);
}
use of com.graphhopper.util.DistanceCalcEarth in project graphhopper by graphhopper.
the class SpatialKeyAlgoTest method testBijectionBug2.
@Test
public void testBijectionBug2() {
for (long i = 4; i <= 64; i += 4) {
SpatialKeyAlgo algo = new SpatialKeyAlgo((int) i);
long keyX = algo.encode(1, 1);
GHPoint coord = new GHPoint();
algo.decode(keyX, coord);
long keyY = algo.encode(coord.lat, coord.lon);
GHPoint coord2 = new GHPoint();
algo.decode(keyY, coord2);
double dist = new DistanceCalcEarth().calcDist(coord.lat, coord.lon, coord2.lat, coord2.lon);
assertEquals(0, dist, 1e-5);
// System.out.println("\n\n##" + i + "\nkeyX:" + BitUtil.BIG.toBitString(keyX));
// System.out.println("keyY:" + BitUtil.BIG.toBitString(keyY));
// System.out.println("distanceX:" + dist + " precision:" + precision + " difference:" + (dist - precision) + " factor:" + dist / precision);
}
}
Aggregations