Class LatLonRect


  • @Immutable
    public class LatLonRect
    extends Object
    Bounding box for latitude/longitude points. This is a rectangle in lat/lon coordinates. This class handles the longitude wrapping problem. The Rectangle always starts from lowerLeft, goes east width degrees until upperRight For latitude, lower < upper. Since the longitude must be in the range +/-180., right may be less or greater than left.
    • Constructor Detail

      • LatLonRect

        public LatLonRect()
        Create a LatLonRect that covers the whole world.
      • LatLonRect

        public LatLonRect​(LatLonPoint p1,
                          double deltaLat,
                          double deltaLon)
        Construct a lat/lon bounding box from a point, and a delta lat, lon. This disambiguates which way the box wraps around the globe.
        Parameters:
        p1 - one corner of the box
        deltaLat - delta lat from p1. (may be positive or negetive)
        deltaLon - delta lon from p1. (may be positive or negetive). A negetive value is interepreted as indicating a wrap, and 360 is added to it.
      • LatLonRect

        public LatLonRect​(double lat0,
                          double lon0,
                          double lat1,
                          double lon1)
        Construct a lat/lon bounding box from unnormalized longitudes.
        Parameters:
        lat0 - lat of starting point
        lon0 - lon of starting point
        lat1 - lat of ending point
        lon1 - lon of ending point
    • Method Detail

      • getUpperRightPoint

        public LatLonPoint getUpperRightPoint()
        Get the upper right corner of the bounding box.
      • getLowerLeftPoint

        public LatLonPoint getLowerLeftPoint()
        Get the lower left corner of the bounding box.
      • getUpperLeftPoint

        public LatLonPoint getUpperLeftPoint()
        Get the upper left corner of the bounding box.
      • getLowerRightPoint

        public LatLonPoint getLowerRightPoint()
        Get the lower left corner of the bounding box.
      • crossDateline

        public boolean crossDateline()
        Get whether the bounding box crosses the +/- 180 seam
      • isAllLongitude

        public boolean isAllLongitude()
        Get whether the bounding box contains all longitudes.
      • getWidth

        public double getWidth()
        return width of bounding box in degrees longitude, always between 0 and 360 degrees.
      • getHeight

        public double getHeight()
        return height of bounding box in degrees latitude, always between 0 and 180 degrees.
      • getCenterLon

        public double getCenterLon()
        return center Longitude, always in the range +/-180
      • getLonMin

        public double getLonMin()
        Get minimum longitude, aka "west" edge. This may be > LonMax when crossDateline is true.
      • getLonMax

        public double getLonMax()
        Get maximum longitude, aka "east" edge.
      • getLatMin

        public double getLatMin()
        Get minimum latitude, aka "south" edge
      • getLatMax

        public double getLatMax()
        Get maximum latitude, aka "north" edge
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • nearlyEquals

        public boolean nearlyEquals​(LatLonRect other,
                                    double maxRelDiff)
        Returns true if this rectangle is nearly equal to other. The "near equality" of corners is determined using LatLonPoint.nearlyEquals(LatLonPoint, double), with the specified maxRelDiff.
        Parameters:
        other - the other rectangle to check.
        maxRelDiff - the maximum relative difference that two corners may have.
        Returns:
        true if this rectangle is nearly equal to other.
      • contains

        public boolean contains​(LatLonPoint p)
        Determine if a specified LatLonPoint is contained in this bounding box.
        Parameters:
        p - the specified point to be tested
        Returns:
        true if point is contained in this bounding box
      • contains

        public boolean contains​(double lat,
                                double lon)
        Determine if the given lat/lon point is contined inside this rectangle.
        Parameters:
        lat - lat of point
        lon - lon of point
        Returns:
        true if the given lat/lon point is contained inside this rectangle
      • containedIn

        public boolean containedIn​(LatLonRect b)
        Determine if this bounding box is contained in another LatLonRect.
        Parameters:
        b - the other box to see if it contains this one
        Returns:
        true if b contained in this bounding box
      • intersect

        @Nullable
        public LatLonRect intersect​(LatLonRect clip)
        Create the intersection of this LatLonRect with another LatLonRect.
        Parameters:
        clip - intersect with this
        Returns:
        intersection, or null if there is no intersection
      • toString1

        public String toString1()
        Return a String representation of this object.
         eg: ll: 90.0S .0E+ ur: 90.0N .0E
         
        Returns:
        a String representation of this object.
      • toString2

        public String toString2()
        Return a String representation of this object.
         lat= [-90.00,90.00] lon= [0.00,360.00
         
        Returns:
        a String representation of this object.
      • toString

        public String toString()
        Return a String representation of this LatLonRect that can be used in LatLonRect.fromSpec(String): "lat, lon, deltaLat, deltaLon"
        Overrides:
        toString in class Object
      • builder

        public static LatLonRect.Builder builder​(LatLonPoint left,
                                                 LatLonPoint right)
        Construct a lat/lon bounding box from two points. The order of longitude coord of the two points matters: pt1.lon is always the "left" point, then points contained within the box increase (unless crossing the Dateline, in which case they jump to -180, but then start increasing again) until pt2.lon. The order of lat doesnt matter: smaller will go to "lower" point (further south). There is an ambiguity when left = right, since LatLonPoint is normalized. Assume this is the full width = 360 case.
        Parameters:
        left - left corner
        right - right corner
      • builder

        public static LatLonRect.Builder builder​(LatLonPoint p1,
                                                 double deltaLat,
                                                 double deltaLon)
        Construct a lat/lon bounding box from a point, and a delta lat, lon. This disambiguates which way the box wraps around the globe.
        Parameters:
        p1 - one corner of the box
        deltaLat - delta lat from p1. (may be positive or negetive)
        deltaLon - delta lon from p1. (may be positive or negetive)
      • builder

        public static LatLonRect.Builder builder​(double lat0,
                                                 double lon0,
                                                 double lat1,
                                                 double lon1)
        Construct a lat/lon bounding box from unnormalized longitude.
        Parameters:
        lat0 - lat of starting point
        lon0 - lon of starting point
        lat1 - lat of ending point
        lon1 - lon of ending point
      • fromSpec

        @Nullable
        public static LatLonRect fromSpec​(String spec)
        Construct a lat/lon bounding box from a string, or null if format is wrong.
        Parameters:
        spec - "lat, lon, deltaLat, deltaLon"