org.geotoolkit.geometry
Class Envelope2D

Object
  extended by RectangularShape
      extended by Rectangle2D
          extended by Rectangle2D.Double
              extended by Envelope2D
All Implemented Interfaces:
Shape, Serializable, Cloneable, Envelope

public class Envelope2D
extends Rectangle2D.Double
implements Envelope, Cloneable

A two-dimensional envelope on top of Rectangle2D. This implementation is provided for inter-operability between Java2D and GeoAPI.

This class inherits x and y fields. But despite their names, they don't need to be oriented toward East and North respectively. The (x,y) axis can have any orientation and should be understood as "ordinate 0" and "ordinate 1" values instead. This is not specific to this implementation; in Java2D too, the visual axis orientation depend on the affine transform in the graphics context.

Since:
2.1
Version:
3.11
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
GeneralEnvelope, jts.ReferencedEnvelope, GeographicBoundingBox, Serialized Form
Module:
referencing/geotk-referencing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
 
Fields inherited from class Rectangle2D.Double
height, width, x, y
 
Fields inherited from class Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
Envelope2D()
          Constructs an initially empty envelope with no CRS.
Envelope2D(CoordinateReferenceSystem crs, double x, double y, double width, double height)
          Constructs two-dimensional envelope defined by the specified coordinates.
Envelope2D(CoordinateReferenceSystem crs, Rectangle2D rect)
          Constructs two-dimensional envelope defined by an other Rectangle2D.
Envelope2D(DirectPosition2D minDP, DirectPosition2D maxDP)
          Constructs two-dimensional envelope defined by the specified coordinates.
Envelope2D(Envelope envelope)
          Constructs two-dimensional envelope defined by an other Envelope.
Envelope2D(GeographicBoundingBox box)
          Constructs a new envelope with the same data than the specified geographic bounding box.
 
Method Summary
 boolean boundsEquals(Envelope that, int xDim, int yDim, double eps)
          Returns true if this envelope bounds is equal to that envelope bounds in two specified dimensions.
 boolean equals(Object object)
          Compares the specified object with this envelope for equality.
 CoordinateReferenceSystem getCoordinateReferenceSystem()
          Returns the coordinate reference system in which the coordinates are given.
 int getDimension()
          Returns the number of dimensions.
 DirectPosition2D getLowerCorner()
          A coordinate position consisting of all the minimal ordinates for each dimension for all points within the Envelope.
 double getMaximum(int dimension)
          Returns the maximal ordinate along the specified dimension.
 double getMedian(int dimension)
          Returns the median ordinate along the specified dimension.
 double getMinimum(int dimension)
          Returns the minimal ordinate along the specified dimension.
 double getSpan(int dimension)
          Returns the envelope span (typically width or height) along the specified dimension.
 DirectPosition2D getUpperCorner()
          A coordinate position consisting of all the maximal ordinates for each dimension for all points within the Envelope.
 int hashCode()
          Returns a hash value for this envelope.
 void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
          Sets the coordinate reference system in which the coordinate are given.
 void setEnvelope(Envelope envelope)
          Sets this envelope to the same values than the given Envelope.
 String toString()
          Formats this envelope in the Well Known Text (WKT) format.
 
Methods inherited from class Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode, setRect, setRect
 
Methods inherited from class Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
 
Methods inherited from class RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Cloneable
clone
 

Constructor Detail

Envelope2D

public Envelope2D()
Constructs an initially empty envelope with no CRS.

Since:
2.5

Envelope2D

public Envelope2D(Envelope envelope)
           throws MismatchedDimensionException
Constructs two-dimensional envelope defined by an other Envelope.

Parameters:
envelope - The envelope to copy.
Throws:
MismatchedDimensionException - If the given envelope is not two-dimensional.

Envelope2D

public Envelope2D(GeographicBoundingBox box)
Constructs a new envelope with the same data than the specified geographic bounding box. The coordinate reference system is set to WGS84.

Parameters:
box - The bounding box to copy.
Since:
3.11

Envelope2D

public Envelope2D(CoordinateReferenceSystem crs,
                  Rectangle2D rect)
Constructs two-dimensional envelope defined by an other Rectangle2D.

Parameters:
crs - The coordinate reference system, or null.
rect - The rectangle to copy.

Envelope2D

public Envelope2D(CoordinateReferenceSystem crs,
                  double x,
                  double y,
                  double width,
                  double height)
Constructs two-dimensional envelope defined by the specified coordinates. Despite their name, the (x,y) coordinates don't need to be oriented toward (East, North). Those parameter names simply match the x and y fields. The actual axis orientations are determined by the specified CRS. See the class javadoc for details.

Parameters:
crs - The coordinate reference system, or null.
x - The x minimal value.
y - The y minimal value.
width - The envelope width.
height - The envelope height.

Envelope2D

public Envelope2D(DirectPosition2D minDP,
                  DirectPosition2D maxDP)
Constructs two-dimensional envelope defined by the specified coordinates. Despite their name, the (x,y) coordinates don't need to be oriented toward (East, North). Those parameter names simply match the x and y fields. The actual axis orientations are determined by the specified CRS. See the class javadoc for details.

The minDP and maxDP arguments usually contains the minimal and maximal ordinate values respectively, but this is not mandatory. The ordinates will be rearanged as needed.

Parameters:
minDP - The fist position.
maxDP - The second position.
Throws:
MismatchedReferenceSystemException - if the two positions don't use the same CRS.
Since:
2.4
Method Detail

setEnvelope

public void setEnvelope(Envelope envelope)
                 throws MismatchedDimensionException
Sets this envelope to the same values than the given Envelope.

Parameters:
envelope - The envelope to copy.
Throws:
MismatchedDimensionException - If the given envelope is not two-dimensional.
Since:
3.09

getCoordinateReferenceSystem

public final CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the coordinate reference system in which the coordinates are given.

Specified by:
getCoordinateReferenceSystem in interface Envelope
Returns:
The coordinate reference system, or null.

setCoordinateReferenceSystem

public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate are given. This method does not reproject the envelope. If the envelope coordinates need to be transformed to the new CRS, consider using CRS.transform(Envelope, CoordinateReferenceSystem) instead.

Parameters:
crs - The new coordinate reference system, or null.

getDimension

public final int getDimension()
Returns the number of dimensions.

Specified by:
getDimension in interface Envelope

getLowerCorner

public DirectPosition2D getLowerCorner()
A coordinate position consisting of all the minimal ordinates for each dimension for all points within the Envelope.

Specified by:
getLowerCorner in interface Envelope
Returns:
The lower corner.

getUpperCorner

public DirectPosition2D getUpperCorner()
A coordinate position consisting of all the maximal ordinates for each dimension for all points within the Envelope.

Specified by:
getUpperCorner in interface Envelope
Returns:
The upper corner.

getMinimum

public final double getMinimum(int dimension)
                        throws IndexOutOfBoundsException
Returns the minimal ordinate along the specified dimension.

Specified by:
getMinimum in interface Envelope
Parameters:
dimension - The dimension to query.
Returns:
The minimal ordinate value along the given dimension.
Throws:
IndexOutOfBoundsException - If the given index is out of bounds.

getMaximum

public final double getMaximum(int dimension)
                        throws IndexOutOfBoundsException
Returns the maximal ordinate along the specified dimension.

Specified by:
getMaximum in interface Envelope
Parameters:
dimension - The dimension to query.
Returns:
The maximal ordinate value along the given dimension.
Throws:
IndexOutOfBoundsException - If the given index is out of bounds.

getMedian

public final double getMedian(int dimension)
                       throws IndexOutOfBoundsException
Returns the median ordinate along the specified dimension. The result should be equals (minus rounding error) to (getMaximum(dimension) - getMinimum(dimension)) / 2.

Specified by:
getMedian in interface Envelope
Parameters:
dimension - The dimension to query.
Returns:
The mid ordinate value along the given dimension.
Throws:
IndexOutOfBoundsException - If the given index is out of bounds.

getSpan

public final double getSpan(int dimension)
                     throws IndexOutOfBoundsException
Returns the envelope span (typically width or height) along the specified dimension. The result should be equals (minus rounding error) to getMaximum(dimension) - getMinimum(dimension).

Specified by:
getSpan in interface Envelope
Parameters:
dimension - The dimension to query.
Returns:
The difference along maximal and minimal ordinates in the given dimension.
Throws:
IndexOutOfBoundsException - If the given index is out of bounds.

hashCode

public int hashCode()
Returns a hash value for this envelope. Current implementation returns the same value than Rectangle2D for consistency with its equals method, which compare arbitrary Rectangle2D implementations.

Overrides:
hashCode in class Rectangle2D

equals

public boolean equals(Object object)
Compares the specified object with this envelope for equality.

Overrides:
equals in class Rectangle2D
Parameters:
object - The object to compare with this envelope.
Returns:
true if the given object is equal to this envelope.

boundsEquals

public boolean boundsEquals(Envelope that,
                            int xDim,
                            int yDim,
                            double eps)
Returns true if this envelope bounds is equal to that envelope bounds in two specified dimensions. The coordinate reference system is not compared, since it doesn't need to have the same number of dimensions.

Parameters:
that - The envelope to compare to.
xDim - The dimension of that envelope to compare to the x dimension of this envelope.
yDim - The dimension of that envelope to compare to the y dimension of this envelope.
eps - A small tolerance number for floating point number comparisons. This value will be scaled according this envelope width and height.
Returns:
true if the envelope bounds are the same (up to the specified tolerance level) in the specified dimensions, or false otherwise.

toString

public String toString()
Formats this envelope in the Well Known Text (WKT) format. The output is like below:
BOX2D(lower corner, upper corner)

Overrides:
toString in class Rectangle2D.Double
Since:
2.4
See Also:
Envelopes.toWKT(Envelope)


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.