Search in sources :

Example 96 with GHPoint

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

the class SpatialKeyAlgoTest method testDifferentInitialBounds.

@Test
public void testDifferentInitialBounds() {
    SpatialKeyAlgo algo = new SpatialKeyAlgo(8).setBounds(0, 5, 0, 5);
    assertEquals(1, algo.encode(0, 0.5));
    assertEquals(5, algo.encode(0, 1));
    GHPoint coord = new GHPoint();
    algo.decode(5, coord);
    assertEquals(5, algo.encode(coord));
    algo.decode(1, coord);
    assertEquals(1, algo.encode(coord));
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 97 with GHPoint

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

the class LocationIndexTree method getCenter.

GHPoint getCenter(double lat, double lon) {
    GHPoint query = new GHPoint(lat, lon);
    long key = keyAlgo.encode(query);
    GHPoint center = new GHPoint();
    keyAlgo.decode(key, center);
    return center;
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 98 with GHPoint

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

the class CompressedArrayTest method testCompress2.

@Test
public void testCompress2() throws Exception {
    CompressedArray arr = new CompressedArray();
    Random rand = new Random(0);
    for (int i = 0; i < 10000; i++) {
        arr.write(i / 1000.0, rand.nextDouble() * 90);
    }
    arr.flush();
    GHPoint coord = arr.get(0);
    assertEquals(0, coord.lat, 1e-6);
    assertEquals(65.787100, coord.lon, 1e-6);
    coord = arr.get(999);
    assertEquals(0.999, coord.lat, 1e-6);
    coord = arr.get(9998);
    assertEquals(9.998, coord.lat, 1e-6);
    coord = arr.get(9999);
    assertEquals(9.999, coord.lat, 1e-6);
    assertNull(arr.get(10000));
// assertEquals(43, arr.calcMemInMB() * Helper.MB, 1e-3);
}
Also used : Random(java.util.Random) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 99 with GHPoint

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

the class CompressedArray method write.

public void write(double lat, double lon) {
    try {
        if (currentWriter == null)
            currentWriter = new VLongStorage(entriesPerSegment * approxBytesPerEntry);
        long latlon = algo.encode(new GHPoint(lat, lon));
        // we cannot use delta encoding as vlong does not support negative numbers
        // but compression of vlong is much more efficient than directly storing the integers
        currentWriter.writeVLong(latlon);
        currentEntry++;
        if (currentEntry >= entriesPerSegment) {
            flush();
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : VLongStorage(com.graphhopper.storage.VLongStorage) GHPoint(com.graphhopper.util.shapes.GHPoint) DataFormatException(java.util.zip.DataFormatException)

Example 100 with GHPoint

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

the class RoundTripRoutingTemplate method generateValidPoint.

private QueryResult generateValidPoint(GHPoint from, double distanceInMeters, double heading, EdgeFilter edgeFilter) {
    int tryCount = 0;
    while (true) {
        GHPoint generatedPoint = Helper.DIST_EARTH.projectCoordinate(from.getLat(), from.getLon(), distanceInMeters, heading);
        QueryResult qr = locationIndex.findClosest(generatedPoint.getLat(), generatedPoint.getLon(), edgeFilter);
        if (qr.isValid())
            return qr;
        tryCount++;
        distanceInMeters *= 0.95;
        if (tryCount >= maxRetries)
            return null;
    }
}
Also used : QueryResult(com.graphhopper.storage.index.QueryResult) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint)

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