protected Node(final Polygon polygon, final int index, final int vertexIndex) { this.idx = index; this.vrtxIdx = vertexIndex; this.polygon = polygon; this.y = encodeLatitude(polygon.getPolyLat(vrtxIdx)); this.x = encodeLongitude(polygon.getPolyLon(vrtxIdx)); this.morton = BitUtil.interleave(x ^ 0x80000000, y ^ 0x80000000); this.previous = null; this.next = null; this.previousZ = null; this.nextZ = null; }
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ public static Rectangle bbox(final String geohash) { // bottom left is the coordinate GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash); int len = Math.min(12, geohash.length()); long ghLong = longEncode(geohash, len); // shift away the level ghLong >>>= 4; // deinterleave long lon = BitUtil.deinterleave(ghLong >>> 1); long lat = BitUtil.deinterleave(ghLong); if (lat < MAX_LAT_BITS) { // add 1 to lat and lon to get topRight GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)(lat + 1), (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon()); } else { // We cannot go north of north pole, so just using 90 degrees instead of calculating it using // add 1 to lon to get lon of topRight, we are going to use 90 for lat GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)lat, (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), MAX_LAT_INCL, bottomLeft.lon(), topRight.lon()); } }
public static final Long mortonHash(final double lon, final double lat) { return BitUtil.interleave(scaleLon(lon), scaleLat(lat)); }
protected Node(final Polygon polygon, final int index, final int vertexIndex) { this.idx = index; this.vrtxIdx = vertexIndex; this.polygon = polygon; this.y = encodeLatitude(polygon.getPolyLat(vrtxIdx)); this.x = encodeLongitude(polygon.getPolyLon(vrtxIdx)); this.morton = BitUtil.interleave(x ^ 0x80000000, y ^ 0x80000000); this.previous = null; this.next = null; this.previousZ = null; this.nextZ = null; }
/** * Quantizes lat/lon points and bit interleaves them into a sortable morton code * ranging from 0x00 : 0xFF... * https://en.wikipedia.org/wiki/Z-order_curve * This is useful for bitwise operations in raster space * @param latitude latitude value: must be within standard +/-90 coordinate bounds. * @param longitude longitude value: must be within standard +/-180 coordinate bounds. * @return bit interleaved encoded values as a 64-bit {@code long} * @throws IllegalArgumentException if latitude or longitude is out of bounds */ public static final long encodeCeil(double latitude, double longitude) { checkLatitude(latitude); checkLongitude(longitude); // encode lat/lon flipping the sign bit so negative ints sort before positive ints final int latEnc = encodeLatitudeCeil(latitude) ^ 0x80000000; final int lonEnc = encodeLongitudeCeil(longitude) ^ 0x80000000; return BitUtil.interleave(lonEnc, latEnc); }
/** * Main encoding method to quantize lat/lon points and bit interleave them into a binary morton code * in the range of 0x00000000... : 0xFFFFFFFF... * * @param latitude latitude value: must be within standard +/-90 coordinate bounds. * @param longitude longitude value: must be within standard +/-180 coordinate bounds. * @return bit interleaved encoded values as a 64-bit {@code long} * @throws IllegalArgumentException if latitude or longitude is out of bounds */ public static final long encode(double latitude, double longitude) { checkLatitude(latitude); checkLongitude(longitude); // encode lat/lon flipping the sign bit so negative ints sort before positive ints final int latEnc = encodeLatitude(latitude) ^ 0x80000000; final int lonEnc = encodeLongitude(longitude) ^ 0x80000000; return BitUtil.interleave(lonEnc, latEnc); }
long minZ = BitUtil.interleave(minTX, minTY); long maxZ = BitUtil.interleave(maxTX, maxTY);
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ public static Rectangle bbox(final String geohash) { // bottom left is the coordinate GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash); int len = Math.min(12, geohash.length()); long ghLong = longEncode(geohash, len); // shift away the level ghLong >>>= 4; // deinterleave long lon = BitUtil.deinterleave(ghLong >>> 1); long lat = BitUtil.deinterleave(ghLong); if (lat < MAX_LAT_BITS) { // add 1 to lat and lon to get topRight GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)(lat + 1), (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon()); } else { // We cannot go north of north pole, so just using 90 degrees instead of calculating it using // add 1 to lon to get lon of topRight, we are going to use 90 for lat GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)lat, (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), MAX_LAT_INCL, bottomLeft.lon(), topRight.lon()); } }
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ public static Rectangle bbox(final String geohash) { // bottom left is the coordinate GeoPoint bottomLeft = GeoPoint.fromGeohash(geohash); int len = Math.min(12, geohash.length()); long ghLong = longEncode(geohash, len); // shift away the level ghLong >>>= 4; // deinterleave long lon = BitUtil.deinterleave(ghLong >>> 1); long lat = BitUtil.deinterleave(ghLong); if (lat < MAX_LAT_BITS) { // add 1 to lat and lon to get topRight GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)(lat + 1), (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), topRight.lat(), bottomLeft.lon(), topRight.lon()); } else { // We cannot go north of north pole, so just using 90 degrees instead of calculating it using // add 1 to lon to get lon of topRight, we are going to use 90 for lat GeoPoint topRight = GeoPoint.fromGeohash(BitUtil.interleave((int)lat, (int)(lon + 1)) << 4 | len); return new Rectangle(bottomLeft.lat(), MAX_LAT_INCL, bottomLeft.lon(), topRight.lon()); } }
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ 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()); }
/** * Computes the bounding box coordinates from a given geohash * * @param geohash Geohash of the defined cell * @return GeoRect rectangle defining the bounding box */ 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()); }
long minZ = BitUtil.interleave(minTX, minTY); long maxZ = BitUtil.interleave(maxTX, maxTY);