|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractEnvelope
GeneralEnvelope
public class GeneralEnvelope
A minimum bounding box or rectangle. Regardless of dimension, an Envelope can
be represented without ambiguity as two direct positions
(coordinate points). To encode an Envelope, it is sufficient to encode these
two points.
Note:This particular implementation ofEnvelopeuses an arbitrary Coordinate Reference System, which doesn't need to be geographic. This is different than theGeographicBoundingBoxclass provided in the metadata package, which can be used as a kind of envelope restricted to a Geographic CRS having Greenwich prime meridian.
Envelope is said "General" because it
uses coordinates of an arbitrary dimension. This is in contrast with Envelope2D,
which can use only two-dimensional coordinates.
A GeneralEnvelope can be created in various ways:
BBOX in
Well Known Text format.
Envelope2D,
jts.ReferencedEnvelope,
DefaultGeographicBoundingBox,
Serialized Form
| referencing/geotk-referencing (download) | View source code for this class |
| Constructor Summary | |
|---|---|
GeneralEnvelope(CoordinateReferenceSystem crs)
Constructs an empty envelope with the specified coordinate reference system. |
|
GeneralEnvelope(double[] minDP,
double[] maxDP)
Constructs a envelope defined by two positions. |
|
GeneralEnvelope(double min,
double max)
Constructs one-dimensional envelope defined by a range of values. |
|
GeneralEnvelope(Envelope envelope)
Constructs a new envelope with the same data than the specified envelope. |
|
GeneralEnvelope(GeneralDirectPosition minDP,
GeneralDirectPosition maxDP)
Constructs a envelope defined by two positions. |
|
GeneralEnvelope(GeographicBoundingBox box)
Constructs a new envelope with the same data than the specified geographic bounding box. |
|
GeneralEnvelope(int dimension)
Constructs an empty envelope of the specified dimension. |
|
GeneralEnvelope(Rectangle2D rect)
Constructs two-dimensional envelope defined by a Rectangle2D. |
|
GeneralEnvelope(String wkt)
Constructs a new envelope initialized to the values parsed from the given string in Well Known Text (WKT) format. |
|
| Method Summary | |
|---|---|
void |
add(DirectPosition position)
Adds a point to this envelope. |
void |
add(Envelope envelope)
Adds an envelope object to this envelope. |
GeneralEnvelope |
clone()
Returns a deep copy of this envelope. |
boolean |
contains(DirectPosition position)
Tests if a specified coordinate is inside the boundary of this envelope. |
boolean |
contains(Envelope envelope,
boolean edgesInclusive)
Returns true if this envelope completely encloses the specified envelope. |
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. |
DirectPosition |
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. |
DirectPosition |
getMedian()
A coordinate position consisting of all the middle ordinates for each dimension for all points within the Envelope. |
double |
getMedian(int dimension)
Returns the median ordinate along the specified dimension. |
double |
getMinimum(int dimension)
Returns the minimal ordinate along the specified dimension. |
GeneralEnvelope |
getReducedEnvelope(int lower,
int upper)
Returns a new envelope with the same values than this envelope minus the specified range of dimensions. |
double |
getSpan(int dimension)
Returns the envelope span (typically width or height) along the specified dimension. |
double |
getSpan(int dimension,
Unit<?> unit)
Returns the envelope span along the specified dimension, in terms of the given units. |
GeneralEnvelope |
getSubEnvelope(int lower,
int upper)
Returns a new envelope that encompass only some dimensions of this envelope. |
DirectPosition |
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 |
intersect(Envelope envelope)
Sets this envelope to the intersection if this envelope with the specified one. |
boolean |
intersects(Envelope envelope,
boolean edgesInclusive)
Returns true if this envelope intersects the specified envelope. |
boolean |
isEmpty()
Determines whether or not this envelope is empty. |
boolean |
isInfinite()
Returns true if at least one ordinate has an
infinite value. |
boolean |
isNull()
Returns false if at least one ordinate value is not NaN. |
boolean |
reduceToDomain(boolean useDomainOfCRS)
Restricts this envelope to the CS or CRS domain of validity. |
void |
roundIfAlmostInteger(double factor,
int maxULP)
Fixes rounding errors up to a given tolerance level. |
void |
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate are given. |
void |
setEnvelope(double... ordinates)
Sets the envelope to the specified values, which must be the lower corner coordinates followed by upper corner coordinates. |
void |
setEnvelope(Envelope envelope)
Sets this envelope to the same coordinate values than the specified envelope. |
void |
setRange(int dimension,
double minimum,
double maximum)
Sets the envelope range along the specified dimension. |
void |
setSubEnvelope(Envelope envelope,
int offset)
Sets a sub-domain of this envelope to the same coordinate values than the specified envelope. |
void |
setToInfinite()
Sets the lower corner to negative infinity and the upper corner to positive infinity. |
void |
setToNull()
Sets all ordinate values to NaN. |
Rectangle2D |
toRectangle2D()
Returns a Rectangle2D with the same bounds as this Envelope. |
| Methods inherited from class AbstractEnvelope |
|---|
equals, toPolygonString, toString, toString |
| Methods inherited from class Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GeneralEnvelope(int dimension)
dimension - The envelope dimension.
public GeneralEnvelope(double min,
double max)
min - The minimal value.max - The maximal value.
public GeneralEnvelope(double[] minDP,
double[] maxDP)
throws IllegalArgumentException
minDP - Minimum ordinate values.maxDP - Maximum ordinate values.
MismatchedDimensionException - if the two positions don't have the same dimension.
IllegalArgumentException - if an ordinate value in the minimum point is not
less than or equal to the corresponding ordinate value in the maximum point.
public GeneralEnvelope(GeneralDirectPosition minDP,
GeneralDirectPosition maxDP)
throws IllegalArgumentException
minDP - Point containing minimum ordinate values.maxDP - Point containing maximum ordinate values.
MismatchedDimensionException - if the two positions don't have the same dimension.
MismatchedReferenceSystemException - if the two positions don't use the same CRS.
IllegalArgumentException - if an ordinate value in the minimum point is not
less than or equal to the corresponding ordinate value in the maximum point.public GeneralEnvelope(CoordinateReferenceSystem crs)
crs - The coordinate reference system.public GeneralEnvelope(Envelope envelope)
envelope - The envelope to copy.public GeneralEnvelope(GeographicBoundingBox box)
box - The bounding box to copy.public GeneralEnvelope(Rectangle2D rect)
Rectangle2D.
The coordinate reference system is initially undefined.
rect - The rectangle to copy.
public GeneralEnvelope(String wkt)
throws NumberFormatException,
IllegalArgumentException
BOX
element like below:
However this constructor is lenient to other geometry types likeBOX(-180 -90, 180 90)
POLYGON.
Actually this constructor ignores the geometry type and just applies the following
simple rules:
,) character.
This constructor does not check the consistency of the provided WKT. For example it doesn't
check that every points in a LINESTRING have the same dimension. However this
constructor ensures that the parenthesis are balanced, in order to catch some malformed WKT.
The following examples can be parsed by this constructor in addition of the standard
BOX element. This constructor creates the bounding box of those geometries:
POINT(6 10)MULTIPOLYGON(((1 1, 5 1, 1 5, 1 1),(2 2, 3 2, 3 3, 2 2)))GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(3 8,7 10))
wkt - The BOX, POLYGON or other kind of element to parse.
NumberFormatException - If a number can not be parsed.
IllegalArgumentException - If the parenthesis are not balanced.AbstractEnvelope.toString(Envelope),
CoordinateFormat| Method Detail |
|---|
public final int getDimension()
getDimension in interface Envelopepublic final CoordinateReferenceSystem getCoordinateReferenceSystem()
getCoordinateReferenceSystem in interface Envelopenull.
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
throws MismatchedDimensionException
reduceToDomain(boolean).
If the envelope coordinates need to be transformed to the new CRS, consider
using CRS.transform(Envelope, CoordinateReferenceSystem) instead.
crs - The new coordinate reference system, or null.
MismatchedDimensionException - if the specified CRS doesn't have the expected
number of dimensions.public boolean reduceToDomain(boolean useDomainOfCRS)
Ensure that the envelope is contained in the coordinate system domain. If some ordinates are out of range, then there is a choice depending on the range meaning:
If crsDomain is true, then the envelope from the previous step
is intersected with the CRS domain of validity, if any.
Envelope users since the lower bounds is numerically greater than the upper bounds.
Reordering as [-175° … 175°] would interchange the meaning of what is "inside" and "outside"
the envelope. So this implementation conservatively expands the range to [-180° … 180°]
in order to ensure that the validated envelope fully contains the original envelope.
useDomainOfCRS - true if the envelope should be restricted to
the CRS domain of validity in addition to the CS domain.
true if this envelope has been modified, or false if no change
was done.
public void roundIfAlmostInteger(double factor,
int maxULP)
ordinates[i]
at dimension i, this method multiplies the ordinate value by the given factor,
then round the result only if the product is close to an integer value. The threshold is
defined by the maxULP argument in ULP units (Unit in the Last Place).
If and only if the product has been rounded, it is divided by the factor and stored in this
envelope in place of the original ordinate.
The code below illustrates the work done on every ordinate values, omitting
(for simplicity) the fact that ordinate[i] is left unchanged if
XMath.roundIfAlmostInteger didn't rounded the product.
This method is useful after envelope calculations subject to rounding errors, like theordinates[i] = XMath.roundIfAlmostInteger(ordinates[i]*factor, maxULP) / factor;
#GeneralEnvelope(GridEnvelope, PixelInCell, MathTransform, CoordinateReferenceSystem)
constructor.
factor - The factor by which to multiply ordinates before rounding
and divide after rounding. A recommended value is 360.maxULP - The maximal change allowed in ULPs (Unit in the Last Place).XMath.roundIfAlmostInteger(double, int)public DirectPosition getLowerCorner()
Envelope.
getLowerCorner in interface EnvelopegetLowerCorner in class AbstractEnvelopepublic DirectPosition getUpperCorner()
Envelope.
getUpperCorner in interface EnvelopegetUpperCorner in class AbstractEnvelopepublic DirectPosition getMedian()
Envelope.
public final double getMinimum(int dimension)
throws IndexOutOfBoundsException
getMinimum in interface Envelopedimension - The dimension to query.
IndexOutOfBoundsException - If the given index is out of bounds.
public final double getMaximum(int dimension)
throws IndexOutOfBoundsException
getMaximum in interface Envelopedimension - The dimension to query.
IndexOutOfBoundsException - If the given index is out of bounds.
public final double getMedian(int dimension)
throws IndexOutOfBoundsException
(getMaximum(dimension) -
getMinimum(dimension)) / 2.
getMedian in interface Envelopedimension - The dimension to query.
IndexOutOfBoundsException - If the given index is out of bounds.
public final double getSpan(int dimension)
throws IndexOutOfBoundsException
getMaximum(dimension) - getMinimum(dimension).
getSpan in interface Envelopedimension - The dimension to query.
IndexOutOfBoundsException - If the given index is out of bounds.
public double getSpan(int dimension,
Unit<?> unit)
throws IndexOutOfBoundsException,
ConversionException
dimension - The dimension to query.unit - The unit for the return value.
IndexOutOfBoundsException - If the given index is out of bounds.
ConversionException - if the length can't be converted to the specified units.
public void setRange(int dimension,
double minimum,
double maximum)
throws IndexOutOfBoundsException
dimension - The dimension to set.minimum - The minimum value along the specified dimension.maximum - The maximum value along the specified dimension.
IndexOutOfBoundsException - If the given index is out of bounds.public void setEnvelope(double... ordinates)
Example: (xmin, ymin, zmin, xmax, ymax, zmax)
ordinates - The new ordinate values.
public void setEnvelope(Envelope envelope)
throws MismatchedDimensionException
envelope - The envelope to copy coordinates from.
MismatchedDimensionException - if the specified envelope doesn't have the expected
number of dimensions.
public void setSubEnvelope(Envelope envelope,
int offset)
throws IndexOutOfBoundsException
lower
inclusive to lower + getDimension() exclusive.
This method ignores the Coordinate Reference System of this and the given envelope.
envelope - The envelope to copy coordinates from.offset - Index of the first dimension to write in this envelope.
IndexOutOfBoundsException - If the given offset is negative, or is greater than
getDimension() - envelope.getDimension().
public GeneralEnvelope getSubEnvelope(int lower,
int upper)
throws IndexOutOfBoundsException
lower and extending to dimension upper-1.
Thus the dimension of the sub-envelope is upper-lower.
lower - The first dimension to copy, inclusive.upper - The last dimension to copy, exclusive.
IndexOutOfBoundsException - if an index is out of bounds.
public GeneralEnvelope getReducedEnvelope(int lower,
int upper)
throws IndexOutOfBoundsException
lower - The first dimension to omit, inclusive.upper - The last dimension to omit, exclusive.
IndexOutOfBoundsException - if an index is out of bounds.public void setToInfinite()
public boolean isInfinite()
true if at least one ordinate has an
infinite value.
true if this envelope has infinite value.public void setToNull()
public boolean isNull()
false if at least one ordinate value is not NaN. The
isNull() check is a little bit different than isEmpty() since it returns
false for a partially initialized envelope, while isEmpty() returns
false only after all dimensions have been initialized. More specifically, the
following rules apply:
isNull() == true, then isEmpty() == trueisEmpty() == false, then isNull() == false
true if this envelope has NaN values.public boolean isEmpty()
true if this envelope is empty.
public void add(DirectPosition position)
throws MismatchedDimensionException
contains(org.opengis.geometry.DirectPosition) 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 have been ignored).
Note: This method assumes that the specified point uses the same CRS than this envelope. For performance reason, it will no be verified unless Java assertions are enabled.
position - The point to add.
MismatchedDimensionException - if the specified point doesn't have
the expected dimension.
public void add(Envelope envelope)
throws MismatchedDimensionException
Envelope objects.
Note: This method assumes that the specified envelope uses the same CRS than this envelope. For performance reason, it will no be verified unless Java assertions are enabled.
envelope - the Envelope to add to this envelope.
MismatchedDimensionException - if the specified envelope doesn't
have the expected dimension.
public boolean contains(DirectPosition position)
throws MismatchedDimensionException
NaN,
then this method returns false.
Note: This method assumes that the specified point uses the same CRS than this envelope. For performance reason, it will no be verified unless Java assertions are enabled.
position - The point to text.
true if the specified coordinates are inside the boundary
of this envelope; false otherwise.
MismatchedDimensionException - if the specified point doesn't have
the expected dimension.
public boolean contains(Envelope envelope,
boolean edgesInclusive)
throws MismatchedDimensionException
true if this envelope completely encloses the specified envelope.
If one or more edges from the specified envelope coincide with an edge from this
envelope, then this method returns true only if edgesInclusive
is true.
Note: This method assumes that the specified envelope uses the same CRS than this envelope. For performance reason, it will no be verified unless Java assertions are enabled.
envelope - The envelope to test for inclusion.edgesInclusive - true if this envelope edges are inclusive.
true if this envelope completely encloses the specified one.
MismatchedDimensionException - if the specified envelope doesn't have
the expected dimension.intersects(Envelope, boolean),
AbstractEnvelope.equals(Envelope, double, boolean)
public boolean intersects(Envelope envelope,
boolean edgesInclusive)
throws MismatchedDimensionException
true if this envelope intersects the specified envelope.
If one or more edges from the specified envelope coincide with an edge from this
envelope, then this method returns true only if edgesInclusive
is true.
Note: This method assumes that the specified envelope uses the same CRS than this envelope. For performance reason, it will no be verified unless Java assertions are enabled.
envelope - The envelope to test for intersection.edgesInclusive - true if this envelope edges are inclusive.
true if this envelope intersects the specified one.
MismatchedDimensionException - if the specified envelope doesn't have
the expected dimension.contains(Envelope, boolean),
AbstractEnvelope.equals(Envelope, double, boolean)
public void intersect(Envelope envelope)
throws MismatchedDimensionException
Note: This method assumes that the specified envelope uses the same CRS than this envelope. For performance reason, it will no be verified unless Java assertions are enabled.
envelope - the Envelope to intersect to this envelope.
MismatchedDimensionException - if the specified envelope doesn't
have the expected dimension.
public Rectangle2D toRectangle2D()
throws IllegalStateException
Rectangle2D with the same bounds as this Envelope.
This envelope must be two-dimensional before this method is invoked.
This is a convenience method for inter-operability with Java2D.
IllegalStateException - if this envelope is not two-dimensional.public int hashCode()
hashCode in class AbstractEnvelopepublic boolean equals(Object object)
equals in class AbstractEnvelopeobject - The object to compare with this envelope.
true if the given object is equal to this envelope.public GeneralEnvelope clone()
clone in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||