Class LatLonBoundingBox

  • All Implemented Interfaces:
    IndexableField

    public class LatLonBoundingBox
    extends Field
    An indexed 2-Dimension Bounding Box field for the Geospatial Lat/Lon Coordinate system

    This field indexes 2-dimension Latitude, Longitude based Geospatial Bounding Boxes. The bounding boxes are defined as minLat, minLon, maxLat, maxLon where min/max lat,lon pairs using double floating point precision.

    Multiple values for the same field in one document is supported.

    This field defines the following static factory methods for common search operations over double ranges:

    • newIntersectsQuery() matches bounding boxes that intersect the defined search bounding box.
    • newWithinQuery() matches bounding boxes that are within the defined search bounding box.
    • newContainsQuery() matches bounding boxes that contain the defined search bounding box.
    • newCrosses() matches bounding boxes that cross the defined search bounding box.

    The following Field limitations and restrictions apply:

    • Dateline wrapping is not supported.
    • Due to an encoding limitation Eastern and Western Hemisphere Bounding Boxes that share the dateline are not supported.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.lucene.document.Field

        Field.Store
    • Constructor Summary

      Constructors 
      Constructor Description
      LatLonBoundingBox​(java.lang.String name, double minLat, double minLon, double maxLat, double maxLon)
      Create a new 2D GeoBoundingBoxField representing a 2 dimensional geospatial bounding box
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static void checkArgs​(double minLat, double minLon, double maxLat, double maxLon)
      validate the two-dimension arguments
      (package private) static void encode​(double lat, double lon, byte[] result, int offset)
      encodes a two-dimensional geopoint (lat, lon) into a byte array
      (package private) static byte[] encode​(double minLat, double minLon, double maxLat, double maxLon)
      encodes a two-dimensional geo bounding box into a byte array
      (package private) static FieldType getType​(int geoDimensions)
      set the field type
      static Query newContainsQuery​(java.lang.String field, double minLat, double minLon, double maxLat, double maxLon)
      Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that contain the defined 2d bounding box
      static Query newCrossesQuery​(java.lang.String field, double minLat, double minLon, double maxLat, double maxLon)
      Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that cross the defined 3d bounding box
      static Query newIntersectsQuery​(java.lang.String field, double minLat, double minLon, double maxLat, double maxLon)
      Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that intersect the defined 3d bounding ranges
      private static Query newRangeQuery​(java.lang.String field, double minLat, double minLon, double maxLat, double maxLon, RangeFieldQuery.QueryType queryType)
      helper method to create a two-dimensional geospatial bounding box query
      static Query newWithinQuery​(java.lang.String field, double minLat, double minLon, double maxLat, double maxLon)
      Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that are within the defined 2d bounding box
      void setRangeValues​(double minLat, double minLon, double maxLat, double maxLon)
      Changes the values of the field
      java.lang.String toString()
      Prints a Field for human consumption.
      private static java.lang.String toString​(byte[] ranges, int dimension)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LatLonBoundingBox

        public LatLonBoundingBox​(java.lang.String name,
                                 double minLat,
                                 double minLon,
                                 double maxLat,
                                 double maxLon)
        Create a new 2D GeoBoundingBoxField representing a 2 dimensional geospatial bounding box
        Parameters:
        name - field name. must not be null
        minLat - minimum latitude value (in degrees); valid in [-90.0 : 90.0]
        minLon - minimum longitude value (in degrees); valid in [-180.0 : 180.0]
        maxLat - maximum latitude value (in degrees); valid in [minLat : 90.0]
        maxLon - maximum longitude value (in degrees); valid in [minLon : 180.0]
    • Method Detail

      • getType

        static FieldType getType​(int geoDimensions)
        set the field type
      • setRangeValues

        public void setRangeValues​(double minLat,
                                   double minLon,
                                   double maxLat,
                                   double maxLon)
        Changes the values of the field
        Parameters:
        minLat - minimum latitude value (in degrees); valid in [-90.0 : 90.0]
        minLon - minimum longitude value (in degrees); valid in [-180.0 : 180.0]
        maxLat - maximum latitude value (in degrees); valid in [minLat : 90.0]
        maxLon - maximum longitude value (in degrees); valid in [minLon : 180.0]
        Throws:
        java.lang.IllegalArgumentException - if min or max is invalid
      • checkArgs

        static void checkArgs​(double minLat,
                              double minLon,
                              double maxLat,
                              double maxLon)
        validate the two-dimension arguments
      • newIntersectsQuery

        public static Query newIntersectsQuery​(java.lang.String field,
                                               double minLat,
                                               double minLon,
                                               double maxLat,
                                               double maxLon)
        Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that intersect the defined 3d bounding ranges
        Parameters:
        field - field name. must not be null
        minLat - minimum latitude value (in degrees); valid in [-90.0 : 90.0]
        minLon - minimum longitude value (in degrees); valid in [-180.0 : 180.0]
        maxLat - maximum latitude value (in degrees); valid in [minLat : 90.0]
        maxLon - maximum longitude value (in degrees); valid in [minLon : 180.0]
        Returns:
        query for matching intersecting 2d bounding boxes
      • newWithinQuery

        public static Query newWithinQuery​(java.lang.String field,
                                           double minLat,
                                           double minLon,
                                           double maxLat,
                                           double maxLon)
        Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that are within the defined 2d bounding box
        Parameters:
        field - field name. must not be null
        minLat - minimum latitude value (in degrees); valid in [-90.0 : 90.0]
        minLon - minimum longitude value (in degrees); valid in [-180.0 : 180.0]
        maxLat - maximum latitude value (in degrees); valid in [minLat : 90.0]
        maxLon - maximum longitude value (in degrees); valid in [minLon : 180.0]
        Returns:
        query for matching 3d bounding boxes that are within the defined bounding box
      • newContainsQuery

        public static Query newContainsQuery​(java.lang.String field,
                                             double minLat,
                                             double minLon,
                                             double maxLat,
                                             double maxLon)
        Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that contain the defined 2d bounding box
        Parameters:
        field - field name. must not be null
        minLat - minimum latitude value (in degrees); valid in [-90.0 : 90.0]
        minLon - minimum longitude value (in degrees); valid in [-180.0 : 180.0]
        maxLat - maximum latitude value (in degrees); valid in [minLat : 90.0]
        maxLon - maximum longitude value (in degrees); valid in [minLon : 180.0]
        Returns:
        query for matching 2d bounding boxes that contain the defined bounding box
      • newCrossesQuery

        public static Query newCrossesQuery​(java.lang.String field,
                                            double minLat,
                                            double minLon,
                                            double maxLat,
                                            double maxLon)
        Create a new 2d query that finds all indexed 2d GeoBoundingBoxField values that cross the defined 3d bounding box
        Parameters:
        field - field name. must not be null
        minLat - minimum latitude value (in degrees); valid in [-90.0 : 90.0]
        minLon - minimum longitude value (in degrees); valid in [-180.0 : 180.0]
        maxLat - maximum latitude value (in degrees); valid in [minLat : 90.0]
        maxLon - maximum longitude value (in degrees); valid in [minLon : 180.0]
        Returns:
        query for matching 2d bounding boxes that cross the defined bounding box
      • newRangeQuery

        private static Query newRangeQuery​(java.lang.String field,
                                           double minLat,
                                           double minLon,
                                           double maxLat,
                                           double maxLon,
                                           RangeFieldQuery.QueryType queryType)
        helper method to create a two-dimensional geospatial bounding box query
      • encode

        static byte[] encode​(double minLat,
                             double minLon,
                             double maxLat,
                             double maxLon)
        encodes a two-dimensional geo bounding box into a byte array
      • encode

        static void encode​(double lat,
                           double lon,
                           byte[] result,
                           int offset)
        encodes a two-dimensional geopoint (lat, lon) into a byte array
      • toString

        public java.lang.String toString()
        Description copied from class: Field
        Prints a Field for human consumption.
        Overrides:
        toString in class Field
      • toString

        private static java.lang.String toString​(byte[] ranges,
                                                 int dimension)