org.apache.lucene.geo

Class GeoEncodingUtils

    • Field Detail

      • BITS

        public static final short BITS
        number of bits used for quantizing latitude and longitude values
        See Also:
        Constant Field Values
    • Method Detail

      • encodeLatitude

        public static int encodeLatitude(double latitude)
        Quantizes double (64 bit) latitude into 32 bits (rounding down: in the direction of -90)
        Parameters:
        latitude - latitude value: must be within standard +/-90 coordinate bounds.
        Returns:
        encoded value as a 32-bit int
        Throws:
        IllegalArgumentException - if latitude is out of bounds
      • encodeLatitudeCeil

        public static int encodeLatitudeCeil(double latitude)
        Quantizes double (64 bit) latitude into 32 bits (rounding up: in the direction of +90)
        Parameters:
        latitude - latitude value: must be within standard +/-90 coordinate bounds.
        Returns:
        encoded value as a 32-bit int
        Throws:
        IllegalArgumentException - if latitude is out of bounds
      • encodeLongitude

        public static int encodeLongitude(double longitude)
        Quantizes double (64 bit) longitude into 32 bits (rounding down: in the direction of -180)
        Parameters:
        longitude - longitude value: must be within standard +/-180 coordinate bounds.
        Returns:
        encoded value as a 32-bit int
        Throws:
        IllegalArgumentException - if longitude is out of bounds
      • encodeLongitudeCeil

        public static int encodeLongitudeCeil(double longitude)
        Quantizes double (64 bit) longitude into 32 bits (rounding up: in the direction of +180)
        Parameters:
        longitude - longitude value: must be within standard +/-180 coordinate bounds.
        Returns:
        encoded value as a 32-bit int
        Throws:
        IllegalArgumentException - if longitude is out of bounds
      • decodeLatitude

        public static double decodeLatitude(int encoded)
        Turns quantized value from encodeLatitude(double) back into a double.
        Parameters:
        encoded - encoded value: 32-bit quantized value.
        Returns:
        decoded latitude value.
      • decodeLatitude

        public static double decodeLatitude(byte[] src,
                                            int offset)
        Turns quantized value from byte array back into a double.
        Parameters:
        src - byte array containing 4 bytes to decode at offset
        offset - offset into src to decode from.
        Returns:
        decoded latitude value.
      • decodeLongitude

        public static double decodeLongitude(int encoded)
        Turns quantized value from encodeLongitude(double) back into a double.
        Parameters:
        encoded - encoded value: 32-bit quantized value.
        Returns:
        decoded longitude value.
      • decodeLongitude

        public static double decodeLongitude(byte[] src,
                                             int offset)
        Turns quantized value from byte array back into a double.
        Parameters:
        src - byte array containing 4 bytes to decode at offset
        offset - offset into src to decode from.
        Returns:
        decoded longitude value.