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