Package org.apache.lucene.geo
Class GeoEncodingUtils
- java.lang.Object
-
- org.apache.lucene.geo.GeoEncodingUtils
-
public final class GeoEncodingUtils extends java.lang.Object
reusable geopoint encoding methods
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GeoEncodingUtils.DistancePredicate
A predicate that checks whether a given point is within a distance of another point.private static class
GeoEncodingUtils.Grid
static class
GeoEncodingUtils.PolygonPredicate
A predicate that checks whether a given point is within a polygon.
-
Field Summary
Fields Modifier and Type Field Description static short
BITS
number of bits used for quantizing latitude and longitude valuesprivate static double
LAT_DECODE
private static double
LAT_SCALE
private static double
LON_DECODE
private static double
LON_SCALE
static int
MAX_LON_ENCODED
static int
MIN_LON_ENCODED
-
Constructor Summary
Constructors Modifier Constructor Description private
GeoEncodingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static int
computeShift(long a, long b)
Compute the minimum shift value so that(b>>>shift)-(a>>>shift)
is less thatARITY
.static GeoEncodingUtils.PolygonPredicate
createComponentPredicate(Component2D tree)
Create a predicate that checks whether points are within a polygon.static GeoEncodingUtils.DistancePredicate
createDistancePredicate(double lat, double lon, double radiusMeters)
Create a predicate that checks whether points are within a distance of a given point.private static GeoEncodingUtils.Grid
createSubBoxes(Rectangle boundingBox, java.util.function.Function<Rectangle,PointValues.Relation> boxToRelation)
static double
decodeLatitude(byte[] src, int offset)
Turns quantized value from byte array back into a double.static double
decodeLatitude(int encoded)
Turns quantized value fromencodeLatitude(double)
back into a double.static double
decodeLongitude(byte[] src, int offset)
Turns quantized value from byte array back into a double.static double
decodeLongitude(int encoded)
Turns quantized value fromencodeLongitude(double)
back into a double.static int
encodeLatitude(double latitude)
Quantizes double (64 bit) latitude into 32 bits (rounding down: in the direction of -90)static int
encodeLatitudeCeil(double latitude)
Quantizes double (64 bit) latitude into 32 bits (rounding up: in the direction of +90)static int
encodeLongitude(double longitude)
Quantizes double (64 bit) longitude into 32 bits (rounding down: in the direction of -180)static int
encodeLongitudeCeil(double longitude)
Quantizes double (64 bit) longitude into 32 bits (rounding up: in the direction of +180)
-
-
-
Field Detail
-
BITS
public static final short BITS
number of bits used for quantizing latitude and longitude values- See Also:
- Constant Field Values
-
LAT_SCALE
private static final double LAT_SCALE
- See Also:
- Constant Field Values
-
LAT_DECODE
private static final double LAT_DECODE
- See Also:
- Constant Field Values
-
LON_SCALE
private static final double LON_SCALE
- See Also:
- Constant Field Values
-
LON_DECODE
private static final double LON_DECODE
- See Also:
- Constant Field Values
-
MIN_LON_ENCODED
public static final int MIN_LON_ENCODED
-
MAX_LON_ENCODED
public static final int MAX_LON_ENCODED
-
-
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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException
- if longitude is out of bounds
-
decodeLatitude
public static double decodeLatitude(int encoded)
Turns quantized value fromencodeLatitude(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 atoffset
offset
- offset intosrc
to decode from.- Returns:
- decoded latitude value.
-
decodeLongitude
public static double decodeLongitude(int encoded)
Turns quantized value fromencodeLongitude(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 atoffset
offset
- offset intosrc
to decode from.- Returns:
- decoded longitude value.
-
createDistancePredicate
public static GeoEncodingUtils.DistancePredicate createDistancePredicate(double lat, double lon, double radiusMeters)
Create a predicate that checks whether points are within a distance of a given point. It works by computing the bounding box around the circle that is defined by the given points/distance and splitting it into between 1024 and 4096 smaller boxes (4096*0.75^2=2304 on average). Then for each sub box, it computes the relation between this box and the distance query. Finally at search time, it first computes the sub box that the point belongs to, most of the time, no distance computation will need to be performed since all points from the sub box will either be in or out of the circle.
-
createComponentPredicate
public static GeoEncodingUtils.PolygonPredicate createComponentPredicate(Component2D tree)
Create a predicate that checks whether points are within a polygon. It works the same way ascreateDistancePredicate(double, double, double)
.
-
createSubBoxes
private static GeoEncodingUtils.Grid createSubBoxes(Rectangle boundingBox, java.util.function.Function<Rectangle,PointValues.Relation> boxToRelation)
-
computeShift
private static int computeShift(long a, long b)
Compute the minimum shift value so that(b>>>shift)-(a>>>shift)
is less thatARITY
.
-
-