public class Envelope2D extends Rectangle2D.Double implements Envelope, Emptiable, Cloneable
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 direction 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.
Envelope2D
objects, they are rectangle with negative width or
height field values. The default implementation of methods listed in the
right column can handle such cases.
![]() |
Supported methods:
|
getMinX()
, getMinY()
, getMaxX()
, getMaxY()
,
getCenterX()
, getCenterY()
, getWidth()
and getHeight()
methods delegate to the above-cited methods.GeneralEnvelope
,
DefaultGeographicBoundingBox
,
Serialized FormDefined in the sis-referencing
module
Rectangle2D.Double, Rectangle2D.Float
height, width, x, y
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
Constructor and Description |
---|
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(DirectPosition lowerCorner,
DirectPosition upperCorner)
Constructs a two-dimensional envelope defined by the specified coordinates.
|
Envelope2D(Envelope envelope)
Constructs a 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.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double px,
double py)
Adds a point to this rectangle.
|
void |
add(Rectangle2D rect)
Adds an other rectangle to this rectangle.
|
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 |
contains(double px,
double py)
Tests if a specified coordinate is inside the boundary of this envelope.
|
boolean |
contains(double rx,
double ry,
double rw,
double rh)
Returns
true if this envelope completely encloses the specified rectangle. |
boolean |
contains(Rectangle2D rect)
Returns
true if this envelope completely encloses the specified rectangle. |
Envelope2D |
createIntersection(Rectangle2D rect)
Returns the intersection of this envelope with the specified rectangle.
|
Envelope2D |
createUnion(Rectangle2D rect)
Returns the union of this envelope with the specified rectangle.
|
boolean |
equals(Object object)
Compares the specified object with this envelope for equality.
|
double |
getCenterX()
Returns the median ordinate value for dimension 0.
|
double |
getCenterY()
Returns the median ordinate value for dimension 1.
|
CoordinateReferenceSystem |
getCoordinateReferenceSystem()
Returns the coordinate reference system in which the coordinates are given.
|
int |
getDimension()
Returns the number of dimensions, which is always 2.
|
double |
getHeight()
Returns the span for dimension 1.
|
DirectPosition2D |
getLowerCorner()
The limits in the direction of decreasing ordinate values for the two dimensions.
|
double |
getMaximum(int dimension)
Returns the maximal ordinate along the specified dimension.
|
double |
getMaxX()
Returns the maximal ordinate value for dimension 0.
|
double |
getMaxY()
Returns the maximal ordinate value for dimension 1.
|
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 |
getMinX()
Returns the minimal ordinate value for dimension 0.
|
double |
getMinY()
Returns the minimal ordinate value for dimension 1.
|
double |
getSpan(int dimension)
Returns the envelope span along the specified dimension.
|
DirectPosition2D |
getUpperCorner()
The limits in the direction of increasing ordinate values for the two dimensions.
|
double |
getWidth()
Returns the span for dimension 0.
|
boolean |
intersects(double rx,
double ry,
double rw,
double rh)
Returns
true if this envelope intersects the specified envelope. |
boolean |
intersects(Rectangle2D rect)
Returns
true if this envelope intersects the specified envelope. |
boolean |
isEmpty()
Determines whether the envelope is empty.
|
void |
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate are given.
|
Rectangle2D.Double[] |
toRectangles()
Returns this envelope as non-empty Java2D rectangle objects.
|
String |
toString()
Formats this envelope as a "
BOX " element. |
getBounds2D, getX, getY, outcode, setRect, setRect
add, getPathIterator, getPathIterator, hashCode, intersect, intersectsLine, intersectsLine, outcode, setFrame, union
clone, contains, getBounds, getFrame, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
public Envelope2D()
public Envelope2D(DirectPosition lowerCorner, DirectPosition upperCorner) throws MismatchedReferenceSystemException, MismatchedDimensionException
lowerCorner
and upperCorner
arguments are not necessarily
the minimal and maximal values respectively.
See the class javadoc about anti-meridian spanning for more details.lowerCorner
- The fist position.upperCorner
- The second position.MismatchedReferenceSystemException
- if the two positions don't use the same CRS.MismatchedDimensionException
- If the two positions are not two-dimensional.public Envelope2D(Envelope envelope) throws MismatchedDimensionException
Envelope
.envelope
- The envelope to copy (can not be null
).MismatchedDimensionException
- If the given envelope is not two-dimensional.public Envelope2D(GeographicBoundingBox box)
box
- The bounding box to copy (can not be null
).public Envelope2D(CoordinateReferenceSystem crs, Rectangle2D rect) throws MismatchedDimensionException
Rectangle2D
.
If the given rectangle has negative width or height, they will be interpreted
as an envelope spanning the anti-meridian.crs
- The coordinate reference system, or null
.rect
- The rectangle to copy (can not be null
).MismatchedDimensionException
- If the given CRS is not two-dimensional.public Envelope2D(CoordinateReferenceSystem crs, double x, double y, double width, double height) throws MismatchedDimensionException
crs
- The coordinate reference system, or null
.x
- The x minimal value.y
- The y minimal value.width
- The envelope width. May be negative for envelope spanning the anti-meridian.height
- The envelope height. May be negative for envelope spanning the anti-meridian.MismatchedDimensionException
- If the given CRS is not two-dimensional.public final CoordinateReferenceSystem getCoordinateReferenceSystem()
getCoordinateReferenceSystem
in interface Envelope
null
.public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Envelopes#transform(Envelope, CoordinateReferenceSystem)
instead.crs
- The new coordinate reference system, or null
.public final int getDimension()
getDimension
in interface Envelope
public DirectPosition2D getLowerCorner()
Envelope
.
The object returned by this method is a copy. Change in the returned position will not affect this envelope, and conversely.
WRAPAROUND
range meaning.getLowerCorner
in interface Envelope
public DirectPosition2D getUpperCorner()
Envelope
.
The object returned by this method is a copy. Change in the returned position will not affect this envelope, and conversely.
WRAPAROUND
range meaning.getUpperCorner
in interface Envelope
public double getMinimum(int dimension) throws IndexOutOfBoundsException
AbstractEnvelope.getMinimum(int)
method.getMinimum
in interface Envelope
dimension
- The dimension to query.IndexOutOfBoundsException
- If the given index is out of bounds.public double getMaximum(int dimension) throws IndexOutOfBoundsException
AbstractEnvelope.getMaximum(int)
method.getMaximum
in interface Envelope
dimension
- The dimension to query.IndexOutOfBoundsException
- If the given index is out of bounds.public double getMedian(int dimension) throws IndexOutOfBoundsException
AbstractEnvelope.getMedian(int)
method.getMedian
in interface Envelope
dimension
- The dimension to query.IndexOutOfBoundsException
- If the given index is out of bounds.public double getSpan(int dimension) throws IndexOutOfBoundsException
AbstractEnvelope.getSpan(int)
method.getSpan
in interface Envelope
dimension
- The dimension to query.IndexOutOfBoundsException
- If the given index is out of bounds.public double getMinX()
getMinX
in class RectangularShape
public double getMinY()
getMinY
in class RectangularShape
public double getMaxX()
getMaxX
in class RectangularShape
public double getMaxY()
getMaxY
in class RectangularShape
public double getCenterX()
getCenterX
in class RectangularShape
public double getCenterY()
getCenterY
in class RectangularShape
public double getWidth()
getWidth
in class Rectangle2D.Double
public double getHeight()
getHeight
in class Rectangle2D.Double
public boolean isEmpty()
Note that if the Rectangle2D.Double.width or Rectangle2D.Double.height value is
NaN
, then the envelope is considered empty.
This is different than the default Rectangle2D.Double.isEmpty()
implementation, which doesn't check for NaN
values.
isEmpty
in interface Emptiable
isEmpty
in class Rectangle2D.Double
true
if this envelope is empty.public Rectangle2D.Double[] toRectangles()
Rectangle2D.Double
in an array of length 1.Rectangle2D.Double
implementation class rather than the Rectangle2D
abstract class because the Envelope2D
class hierarchy already exposes this implementation choice.this
.AbstractEnvelope.toSimpleEnvelopes()
public boolean contains(double px, double py)
NaN
, then this method returns
false
.
AbstractEnvelope.contains(DirectPosition)
.contains
in interface Shape
contains
in class Rectangle2D
px
- The first ordinate value of the point to text.py
- The second ordinate value of the point to text.true
if the specified coordinate is inside the boundary
of this envelope; false
otherwise.public boolean contains(Rectangle2D rect)
true
if this envelope completely encloses the specified rectangle. If this
envelope or the given rectangle have at least one NaN
value,
then this method returns false
.
AbstractEnvelope.contains(Envelope)
.contains
in interface Shape
contains
in class RectangularShape
rect
- The rectangle to test for inclusion.true
if this envelope completely encloses the specified rectangle.public boolean contains(double rx, double ry, double rw, double rh)
true
if this envelope completely encloses the specified rectangle. If this
envelope or the given rectangle have at least one NaN
value,
then this method returns false
.
AbstractEnvelope.contains(Envelope)
.contains
in interface Shape
contains
in class Rectangle2D
rx
- The x ordinate of the lower corner of the rectangle to test for inclusion.ry
- The y ordinate of the lower corner of the rectangle to test for inclusion.rw
- The width of the rectangle to test for inclusion. May be negative if the rectangle spans the anti-meridian.rh
- The height of the rectangle to test for inclusion. May be negative.true
if this envelope completely encloses the specified one.public boolean intersects(Rectangle2D rect)
true
if this envelope intersects the specified envelope. If this envelope
or the given rectangle have at least one NaN
value, then this
method returns false
.
AbstractEnvelope.intersects(Envelope)
.intersects
in interface Shape
intersects
in class RectangularShape
rect
- The rectangle to test for intersection.true
if this envelope intersects the specified rectangle.public boolean intersects(double rx, double ry, double rw, double rh)
true
if this envelope intersects the specified envelope. If this envelope
or the given rectangle have at least one NaN
value, then this
method returns false
.
AbstractEnvelope.intersects(Envelope)
.intersects
in interface Shape
intersects
in class Rectangle2D
rx
- The x ordinate of the lower corner of the rectangle to test for intersection.ry
- The y ordinate of the lower corner of the rectangle to test for intersection.rw
- The width of the rectangle to test for inclusion. May be negative if the rectangle spans the anti-meridian.rh
- The height of the rectangle to test for inclusion. May be negative.true
if this envelope intersects the specified rectangle.public Envelope2D createIntersection(Rectangle2D rect)
NaN
values, then this
method returns an empty envelope.
GeneralEnvelope.intersect(Envelope)
.createIntersection
in class Rectangle2D.Double
rect
- The rectangle to be intersected with this envelope.public Envelope2D createUnion(Rectangle2D rect)
add(Rectangle2D)
.createUnion
in class Rectangle2D.Double
rect
- The rectangle to add to this envelope.public void add(Rectangle2D rect)
Rectangle
objects.
GeneralEnvelope.add(Envelope)
, except if the result is a rectangle expanding to
infinities. In the later case, the field values are set to NaN
because infinite
values are a little bit problematic in Rectangle2D
objects.add
in class Rectangle2D
rect
- The rectangle to add to this envelope.public void add(double px, double py)
After adding a point, a call to contains(double, double)
with the added point
as an argument will return true
, except if one of the point ordinates was
Double.NaN
in which case the corresponding ordinate has been ignored.
GeneralEnvelope.add(DirectPosition)
.add
in class Rectangle2D
px
- The first ordinate of the point to add.py
- The second ordinate of the point to add.public boolean equals(Object object)
Envelope2D
, then the two objects are compared as plain rectangles,
i.e. the coordinate reference system of this
envelope is ignored.
hashCode()
Rectangle2D.hashCode()
method for consistency with the
Rectangle2D.equals(Object)
method, which compare arbitrary Rectangle2D
implementations.equals
in class Rectangle2D
object
- The object to compare with this envelope.true
if the given object is equal to this envelope.public boolean boundsEquals(Envelope that, int xDim, int yDim, double eps)
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.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.true
if the envelope bounds are the same (up to the specified tolerance
level) in the specified dimensions, or false
otherwise.public String toString()
BOX
" element.
The output is of the form "BOX(
lower corner,
upper corner)
".
Example:
BOX(-90 -180, 90 180)
toString
in class Rectangle2D.Double
Envelopes.toString(Envelope)
Copyright © 2010–2014 The Apache Software Foundation. All rights reserved.