Package ucar.unidata.geoloc
Class LatLonRect
- java.lang.Object
-
- ucar.unidata.geoloc.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LatLonRect.Builder
-
Field Summary
Fields Modifier and Type Field Description static LatLonRect
INVALID
-
Constructor Summary
Constructors Constructor Description LatLonRect()
Create a LatLonRect that covers the whole world.LatLonRect(double lat0, double lon0, double lat1, double lon1)
Construct a lat/lon bounding box from unnormalized longitudes.LatLonRect(LatLonPoint p1, double deltaLat, double deltaLon)
Construct a lat/lon bounding box from a point, and a delta lat, lon.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LatLonRect.Builder
builder(double lat0, double lon0, double lat1, double lon1)
Construct a lat/lon bounding box from unnormalized longitude.static LatLonRect.Builder
builder(LatLonPoint p1, double deltaLat, double deltaLon)
Construct a lat/lon bounding box from a point, and a delta lat, lon.static LatLonRect.Builder
builder(LatLonPoint left, LatLonPoint right)
Construct a lat/lon bounding box from two points.boolean
containedIn(LatLonRect b)
Determine if this bounding box is contained in another LatLonRect.boolean
contains(double lat, double lon)
Determine if the given lat/lon point is contined inside this rectangle.boolean
contains(LatLonPoint p)
Determine if a specified LatLonPoint is contained in this bounding box.boolean
crossDateline()
Get whether the bounding box crosses the +/- 180 seamboolean
equals(Object o)
static LatLonRect
fromSpec(String spec)
Construct a lat/lon bounding box from a string, or null if format is wrong.double
getCenterLon()
return center Longitude, always in the range +/-180double
getHeight()
return height of bounding box in degrees latitude, always between 0 and 180 degrees.double
getLatMax()
Get maximum latitude, aka "north" edgedouble
getLatMin()
Get minimum latitude, aka "south" edgedouble
getLonMax()
Get maximum longitude, aka "east" edge.double
getLonMin()
Get minimum longitude, aka "west" edge.LatLonPoint
getLowerLeftPoint()
Get the lower left corner of the bounding box.LatLonPoint
getLowerRightPoint()
Get the lower left corner of the bounding box.LatLonPoint
getUpperLeftPoint()
Get the upper left corner of the bounding box.LatLonPoint
getUpperRightPoint()
Get the upper right corner of the bounding box.double
getWidth()
return width of bounding box in degrees longitude, always between 0 and 360 degrees.int
hashCode()
LatLonRect
intersect(LatLonRect clip)
Create the intersection of this LatLonRect with another LatLonRect.boolean
isAllLongitude()
Get whether the bounding box contains all longitudes.boolean
nearlyEquals(LatLonRect other)
Returns the result ofnearlyEquals(LatLonRect, double)
, withMisc.defaultMaxRelativeDiffFloat
.boolean
nearlyEquals(LatLonRect other, double maxRelDiff)
Returnstrue
if this rectangle is nearly equal toother
.LatLonRect.Builder
toBuilder()
Convert to a mutable BuilderString
toString()
Return a String representation of this LatLonRect that can be used in LatLonRect.fromSpec(String): "lat, lon, deltaLat, deltaLon"String
toString1()
Return a String representation of this object.String
toString2()
Return a String representation of this object.
-
-
-
Field Detail
-
INVALID
public static LatLonRect INVALID
-
-
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 boxdeltaLat
- 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 pointlon0
- lon of starting pointlat1
- lat of ending pointlon1
- 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
-
nearlyEquals
public boolean nearlyEquals(LatLonRect other)
Returns the result ofnearlyEquals(LatLonRect, double)
, withMisc.defaultMaxRelativeDiffFloat
.
-
nearlyEquals
public boolean nearlyEquals(LatLonRect other, double maxRelDiff)
Returnstrue
if this rectangle is nearly equal toother
. The "near equality" of corners is determined usingLatLonPoint.nearlyEquals(LatLonPoint, double)
, with the specified maxRelDiff.- Parameters:
other
- the other rectangle to check.maxRelDiff
- the maximumrelative difference
that two corners may have.- Returns:
true
if this rectangle is nearly equal toother
.
-
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 pointlon
- 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"
-
toBuilder
public LatLonRect.Builder toBuilder()
Convert to a mutable Builder
-
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 cornerright
- 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 boxdeltaLat
- 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 pointlon0
- lon of starting pointlat1
- lat of ending pointlon1
- 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"
-
-