ucar.unidata.geoloc
Class LatLonRect

java.lang.Object
  extended by ucar.unidata.geoloc.LatLonRect

public class LatLonRect
extends java.lang.Object

Bounding box for latitude/longitude points. This is a rectangle in lat/lon coordinates. This class handles the longitude wrapping problem. Note that LatLonPoint always has lon in the range +/-180.

Author:
Russ Rew, John Caron

Constructor Summary
LatLonRect()
          Create a LatLonRect that covers the whole world.
LatLonRect(LatLonPoint p1, double deltaLat, double deltaLon)
          Construct a lat/lon bounding box from a point, and a delta lat, lon.
LatLonRect(LatLonPoint left, LatLonPoint right)
          Construct a lat/lon bounding box from two points.
LatLonRect(LatLonRect r)
          Copy Constructor
LatLonRect(java.lang.String spec)
          Construct a lat/lon bounding box from a string.
 
Method Summary
 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 seam
 boolean equals(LatLonRect other)
          get whether two bounding boxes are equal in values
 void extend(LatLonPoint p)
          Extend the bounding box to contain this point
 void extend(LatLonRect r)
          Extend the bounding box to contain the given rectangle
 double getCenterLon()
          return center Longitude, always in the range +/-180
 double getHeight()
          return height of bounding box, always between 0 and 180 degrees.
 double getLatMax()
          Get maximum latitude, aka "north" edge
 double getLatMin()
          Get minimum latitude, aka "south" edge
 double getLonMax()
          Get maximum longitude, aka "east" edge
 double getLonMin()
          Get minimum longitude, aka "west" edge
 LatLonPointImpl getLowerLeftPoint()
          Get the lower left corner of the bounding box.
 LatLonPointImpl getLowerRightPoint()
          Get the lower left corner of the bounding box.
 LatLonPointImpl getUpperLeftPoint()
          Get the upper left corner of the bounding box.
 LatLonPointImpl getUpperRightPoint()
          Get the upper right corner of the bounding box.
 double getWidth()
          return width of bounding box, always between 0 and 360 degrees.
 LatLonRect intersect(LatLonRect clip)
          Create the instersection of this LatLon with the given one
 java.lang.String toString()
          Return a String representation of this object.
 java.lang.String toString2()
          Return a String representation of this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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)

LatLonRect

public LatLonRect(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)

Parameters:
left - left corner
right - right corner

LatLonRect

public LatLonRect(java.lang.String spec)
Construct a lat/lon bounding box from a string.

Parameters:
spec - "lat, lon, deltaLat, deltaLon"
See Also:
LatLonRect(LatLonPoint p1, double deltaLat, double deltaLon)

LatLonRect

public LatLonRect(LatLonRect r)
Copy Constructor

Parameters:
r - rectangle to copy

LatLonRect

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

Method Detail

getUpperRightPoint

public LatLonPointImpl getUpperRightPoint()
Get the upper right corner of the bounding box.

Returns:
upper right corner of the bounding box

getLowerLeftPoint

public LatLonPointImpl getLowerLeftPoint()
Get the lower left corner of the bounding box.

Returns:
lower left corner of the bounding box

getUpperLeftPoint

public LatLonPointImpl getUpperLeftPoint()
Get the upper left corner of the bounding box.

Returns:
upper left corner of the bounding box

getLowerRightPoint

public LatLonPointImpl getLowerRightPoint()
Get the lower left corner of the bounding box.

Returns:
lower left corner of the bounding box

crossDateline

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

Returns:
true if the bounding box crosses the +/- 180 seam

equals

public boolean equals(LatLonRect other)
get whether two bounding boxes are equal in values

Parameters:
other - other bounding box
Returns:
true if this represents the same bounding box as other

getWidth

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

Returns:
width of bounding box in degrees longitude

getHeight

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

Returns:
height of bounding box in degrees latitude

getCenterLon

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

Returns:
center Longitude

getLonMin

public double getLonMin()
Get minimum longitude, aka "west" edge

Returns:
minimum longitude

getLonMax

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

Returns:
maximum longitude

getLatMin

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

Returns:
minimum latitude

getLatMax

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

Returns:
maximum latitude

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 contined 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

extend

public void extend(LatLonPoint p)
Extend the bounding box to contain this point

Parameters:
p - point to include

extend

public void extend(LatLonRect r)
Extend the bounding box to contain the given rectangle

Parameters:
r - rectangle to include

intersect

public LatLonRect intersect(LatLonRect clip)
Create the instersection of this LatLon with the given one

Parameters:
clip - intersect with this
Returns:
intersection, or null if there is no intersection

toString

public java.lang.String toString()
Return a String representation of this object.
eg: ll: 90.0S .0E+ ur: 90.0N .0E

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this object.

toString2

public java.lang.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.