Search in sources :

Example 1 with VLongStorage

use of com.graphhopper.storage.VLongStorage in project graphhopper by graphhopper.

the class CompressedArray method get.

public GHPoint get(long index) {
    int segmentNo = (int) (index / entriesPerSegment);
    int entry = (int) (index % entriesPerSegment);
    try {
        if (segmentNo >= segments.size()) {
            return null;
        }
        byte[] bytes = segments.get(segmentNo);
        VLongStorage store = new VLongStorage(decompress(bytes));
        long len = store.getLength();
        for (int i = 0; store.getPosition() < len; i++) {
            long latlon = store.readVLong();
            if (i == entry) {
                GHPoint point = new GHPoint();
                algo.decode(latlon, point);
                return point;
            }
        }
        return null;
    } catch (ArrayIndexOutOfBoundsException ex) {
        throw new RuntimeException("index " + index + "=> segNo:" + segmentNo + ", entry=" + entry + ", segments:" + segments.size(), ex);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : VLongStorage(com.graphhopper.storage.VLongStorage) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) DataFormatException(java.util.zip.DataFormatException)

Example 2 with VLongStorage

use of com.graphhopper.storage.VLongStorage 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)

Aggregations

VLongStorage (com.graphhopper.storage.VLongStorage)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 DataFormatException (java.util.zip.DataFormatException)2