Example usage for org.apache.lucene.geo GeoEncodingUtils decodeLongitude

List of usage examples for org.apache.lucene.geo GeoEncodingUtils decodeLongitude

Introduction

In this page you can find the example usage for org.apache.lucene.geo GeoEncodingUtils decodeLongitude.

Prototype

public static double decodeLongitude(int encoded) 

Source Link

Document

Turns quantized value from #encodeLongitude back into a double.

Usage

From source file:org.elasticsearch.index.fielddata.plain.LatLonPointDVAtomicFieldData.java

License:Apache License

@Override
public MultiGeoPointValues getGeoPointValues() {
    return new MultiGeoPointValues() {
        GeoPoint[] points = new GeoPoint[0];
        private int count = 0;

        @Override//  w w w . ja  v a 2 s.c o m
        public void setDocument(int docId) {
            values.setDocument(docId);
            count = values.count();
            if (count > points.length) {
                final int previousLength = points.length;
                points = Arrays.copyOf(points,
                        ArrayUtil.oversize(count, RamUsageEstimator.NUM_BYTES_OBJECT_REF));
                for (int i = previousLength; i < points.length; ++i) {
                    points[i] = new GeoPoint(Double.NaN, Double.NaN);
                }
            }
            long encoded;
            for (int i = 0; i < count; ++i) {
                encoded = values.valueAt(i);
                points[i].reset(GeoEncodingUtils.decodeLatitude((int) (encoded >>> 32)),
                        GeoEncodingUtils.decodeLongitude((int) encoded));
            }
        }

        @Override
        public int count() {
            return count;
        }

        @Override
        public GeoPoint valueAt(int index) {
            return points[index];
        }
    };
}

From source file:org.elasticsearch.search.aggregations.metrics.geocentroid.InternalGeoCentroidTests.java

License:Apache License

@Override
protected InternalGeoCentroid createTestInstance(String name, List<PipelineAggregator> pipelineAggregators,
        Map<String, Object> metaData) {
    GeoPoint centroid = RandomGeoGenerator.randomPoint(random());

    // Re-encode lat/longs to avoid rounding issue when testing InternalGeoCentroid#hashCode() and
    // InternalGeoCentroid#equals()
    int encodedLon = GeoEncodingUtils.encodeLongitude(centroid.lon());
    centroid.resetLon(GeoEncodingUtils.decodeLongitude(encodedLon));
    int encodedLat = GeoEncodingUtils.encodeLatitude(centroid.lat());
    centroid.resetLat(GeoEncodingUtils.decodeLatitude(encodedLat));
    long count = randomIntBetween(0, 1000);
    if (count == 0) {
        centroid = null;//w  ww.j av  a2s.  com
    }
    return new InternalGeoCentroid(name, centroid, count, Collections.emptyList(), Collections.emptyMap());
}