Example usage for org.apache.lucene.util BitUtil deinterleave

List of usage examples for org.apache.lucene.util BitUtil deinterleave

Introduction

In this page you can find the example usage for org.apache.lucene.util BitUtil deinterleave.

Prototype

public static long deinterleave(long b) 

Source Link

Document

Extract just the even-bits value as a long from the bit-interleaved value

Usage

From source file:org.codelibs.elasticsearch.common.geo.GeoHashUtils.java

License:Apache License

/**
 * Computes the bounding box coordinates from a given geohash
 *
 * @param geohash Geohash of the defined cell
 * @return GeoRect rectangle defining the bounding box
 *//*from  ww  w.j  a  va2  s.  co  m*/
public static Rectangle bbox(final String geohash) {
    // bottom left is the coordinate
    GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash);
    long ghLong = longEncode(geohash);
    // shift away the level
    ghLong >>>= 4;
    // deinterleave and add 1 to lat and lon to get topRight
    long lat = BitUtil.deinterleave(ghLong >>> 1) + 1;
    long lon = BitUtil.deinterleave(ghLong) + 1;
    GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int) lon, (int) lat) << 4 | geohash.length());

    return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon());
}