Search in sources :

Example 91 with GHPoint

use of com.graphhopper.util.shapes.GHPoint 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);
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) DistanceCalcEarth(com.graphhopper.util.DistanceCalcEarth)

Example 92 with GHPoint

use of com.graphhopper.util.shapes.GHPoint 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);
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) DistanceCalcEarth(com.graphhopper.util.DistanceCalcEarth) Test(org.junit.Test)

Example 93 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class SpatialKeyAlgoTest method testNoFurtherIterationIfBitsIs1.

@Test
public void testNoFurtherIterationIfBitsIs1() {
    SpatialKeyAlgo algo = new SpatialKeyAlgo(4).setBounds(0, 5, 0, 5);
    // 1001
    GHPoint coord = new GHPoint();
    algo.decode(9, coord);
    assertEquals(3.125, coord.lat, 1e-4);
    assertEquals(1.875, coord.lon, 1e-4);
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 94 with GHPoint

use of com.graphhopper.util.shapes.GHPoint 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);
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) DistanceCalcEarth(com.graphhopper.util.DistanceCalcEarth) Test(org.junit.Test)

Example 95 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class SpatialKeyAlgoTest method testEncode4BytesPrecision.

@Test
public void testEncode4BytesPrecision() {
    int bits = 4 * 8;
    SpatialKeyAlgo algo = new SpatialKeyAlgo(bits);
    float lat = 24.235345f;
    float lon = 47.234234f;
    long val = algo.encode(lat, lon);
    assertEquals("11001100000010010110101100111110", BitUtil.BIG.toLastBitString(val, bits));
    GHPoint fl = new GHPoint();
    algo.decode(val, fl);
    assertEquals(lat, fl.lat, 1e-2);
    assertEquals(lon, fl.lon, 1e-2);
    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);
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) DistanceCalcEarth(com.graphhopper.util.DistanceCalcEarth) Test(org.junit.Test)

Aggregations

GHPoint (com.graphhopper.util.shapes.GHPoint)100 Test (org.junit.Test)52 GHRequest (com.graphhopper.GHRequest)25 GHResponse (com.graphhopper.GHResponse)23 QueryResult (com.graphhopper.storage.index.QueryResult)16 PathWrapper (com.graphhopper.PathWrapper)10 DistanceCalcEarth (com.graphhopper.util.DistanceCalcEarth)5 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)4 PointList (com.graphhopper.util.PointList)4 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)4 BBox (com.graphhopper.util.shapes.BBox)4 ArrayList (java.util.ArrayList)4 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Graph (com.graphhopper.storage.Graph)2