@Immutable public final class ImmutableEnvelope extends AbstractEnvelope implements Serializable
Note: WhileImmutableEnvelope
objects are immutable, they contain references toCoordinateReferenceSystem
objects which are not guaranteed to be immutable. For better safety, factory codes are encouraged to pass only immutable instances of coordinate reference systems to the constructors.
Defined in the sis-referencing module
Constructor and Description |
---|
ImmutableEnvelope(CoordinateReferenceSystem crs,
CharSequence wkt)
Constructs a new envelope initialized to the values parsed from the given string in
BOX or Well Known Text (WKT) format. |
ImmutableEnvelope(CoordinateReferenceSystem crs,
Envelope envelope)
Creates an immutable envelope with the ordinate values of the given envelope but
a different CRS.
|
ImmutableEnvelope(DirectPosition lowerCorner,
DirectPosition upperCorner)
Constructs an envelope defined by two corners given as direct positions.
|
ImmutableEnvelope(double[] lowerCorner,
double[] upperCorner,
CoordinateReferenceSystem crs)
Constructs an envelope defined by two corners given as sequences of ordinate values.
|
ImmutableEnvelope(Envelope envelope)
Creates an immutable envelope with the values of the given envelope.
|
ImmutableEnvelope(GeographicBoundingBox box)
Constructs a new envelope with the same data than the specified geographic bounding box.
|
Modifier and Type | Method and Description |
---|---|
static ImmutableEnvelope |
castOrCopy(Envelope envelope)
Returns the given envelope as an
ImmutableEnvelope instance. |
boolean |
equals(Object object)
Returns
true if the specified object is an envelope of the same class
with equals coordinates and CRS. |
CoordinateReferenceSystem |
getCoordinateReferenceSystem()
Returns the envelope coordinate reference system, or
null if unknown. |
int |
getDimension()
Returns the length of coordinate sequence (the number of entries) in this envelope.
|
double |
getLower(int dimension)
Returns the limit in the direction of decreasing ordinate values in the specified dimension.
|
double |
getMaximum(int dimension)
Returns the maximal ordinate value for the specified dimension.
|
double |
getMedian(int dimension)
Returns the median ordinate along the specified dimension.
|
double |
getMinimum(int dimension)
Returns the minimal ordinate value for the specified dimension.
|
double |
getSpan(int dimension)
Returns the envelope span (typically width or height) along the specified dimension.
|
double |
getUpper(int dimension)
Returns the limit in the direction of increasing ordinate values in the specified dimension.
|
int |
hashCode()
Returns a hash value for this envelope.
|
boolean |
isAllNaN()
Returns
false if at least one ordinate value is not NaN. |
boolean |
isEmpty()
Determines whether or not this envelope is empty.
|
String |
toString()
Formats this envelope as a "
BOX " element. |
contains, contains, equals, getLowerCorner, getMedian, getSpan, getUpperCorner, intersects
public ImmutableEnvelope(DirectPosition lowerCorner, DirectPosition upperCorner) throws MismatchedDimensionException, MismatchedReferenceSystemException
lowerCorner
- The limits in the direction of decreasing ordinate values for each dimension.upperCorner
- The limits in the direction of increasing ordinate values for each dimension.MismatchedDimensionException
- If the two positions do not have the same dimension.MismatchedReferenceSystemException
- If the CRS of the two position are not equal.public ImmutableEnvelope(double[] lowerCorner, double[] upperCorner, CoordinateReferenceSystem crs) throws MismatchedDimensionException
lowerCorner
- The limits in the direction of decreasing ordinate values for each dimension.upperCorner
- The limits in the direction of increasing ordinate values for each dimension.crs
- The CRS to assign to this envelope, or null
.MismatchedDimensionException
- If the two sequences do not have the same length, or
if the dimension of the given CRS is not equals to the dimension of the given corners.public ImmutableEnvelope(GeographicBoundingBox box)
"CRS:84"
.box
- The bounding box to copy.public ImmutableEnvelope(Envelope envelope)
ImmutableEnvelope
. In case of doubt,
consider using castOrCopy(Envelope)
instead.envelope
- The envelope to copy.castOrCopy(Envelope)
public ImmutableEnvelope(CoordinateReferenceSystem crs, Envelope envelope) throws MismatchedDimensionException
The main purpose of this method is to assign a non-null CRS when the envelope to copy has a null CRS.
crs
- The CRS to assign to this envelope, or null
.envelope
- The envelope from which to copy ordinate values.MismatchedDimensionException
- If the dimension of the given CRS is not equals
to the dimension of the given envelope.public ImmutableEnvelope(CoordinateReferenceSystem crs, CharSequence wkt) throws IllegalArgumentException, MismatchedDimensionException
BOX
or Well Known Text (WKT) format. The given string is typically
a BOX
element like below:
However this constructor is lenient to other geometry types likeBOX(-180 -90, 180 90)
POLYGON
.
See the javadoc of the GeneralEnvelope
constructor for more information.crs
- The coordinate reference system, or null
if none.wkt
- The BOX
, POLYGON
or other kind of element to parse.IllegalArgumentException
- If the given string can not be parsed.MismatchedDimensionException
- If the dimension of the given CRS is not equals
to the dimension of the parsed envelope.public static ImmutableEnvelope castOrCopy(Envelope envelope)
ImmutableEnvelope
instance. If the given envelope
is already an instance of ImmutableEnvelope
, then it is returned unchanged.
Otherwise the coordinate values and the CRS of the given envelope are copied in a
new envelope.envelope
- The envelope to cast, or null
.ImmutableEnvelope
instance.AbstractEnvelope.castOrCopy(Envelope)
,
GeneralEnvelope.castOrCopy(Envelope)
public int getDimension()
getDimension
in interface Envelope
public CoordinateReferenceSystem getCoordinateReferenceSystem()
null
if unknown.
If non-null, it shall be the same as lower corner
and upper corner CRS.getCoordinateReferenceSystem
in interface Envelope
null
if unknown.public double getLower(int dimension) throws IndexOutOfBoundsException
getLower
in class AbstractEnvelope
dimension
- The dimension for which to obtain the ordinate value.IndexOutOfBoundsException
- If the given index is negative or is equals or greater
than the envelope dimension.public double getUpper(int dimension) throws IndexOutOfBoundsException
getUpper
in class AbstractEnvelope
dimension
- The dimension for which to obtain the ordinate value.IndexOutOfBoundsException
- If the given index is negative or is equals or greater
than the envelope dimension.public double getMinimum(int dimension) throws IndexOutOfBoundsException
AbstractEnvelope.getLower(int)
value verbatim. In the case of envelope spanning the anti-meridian,
this method returns the axis minimum value.getMinimum
in interface Envelope
getMinimum
in class AbstractEnvelope
dimension
- The dimension for which to obtain the ordinate value.IndexOutOfBoundsException
- If the given index is negative or is equals or greater
than the envelope dimension.public double getMaximum(int dimension) throws IndexOutOfBoundsException
AbstractEnvelope.getUpper(int)
value verbatim. In the case of envelope spanning the anti-meridian,
this method returns the axis maximum value.getMaximum
in interface Envelope
getMaximum
in class AbstractEnvelope
dimension
- The dimension for which to obtain the ordinate value.IndexOutOfBoundsException
- If the given index is negative or is equals or greater
than the envelope dimension.public double getMedian(int dimension) throws IndexOutOfBoundsException
median = (getUpper(dimension) + getLower(dimension)) / 2;
WRAPAROUND
, then this method returns
NaN
.getMedian
in interface Envelope
getMedian
in class AbstractEnvelope
dimension
- The dimension for which to obtain the ordinate value.Double.NaN
.IndexOutOfBoundsException
- If the given index is negative or is equals or greater
than the envelope dimension.public double getSpan(int dimension) throws IndexOutOfBoundsException
span = getUpper(dimension) - getLower(dimension);
NaN
.getSpan
in interface Envelope
getSpan
in class AbstractEnvelope
dimension
- The dimension for which to obtain the span.Double.NaN
.IndexOutOfBoundsException
- If the given index is negative or is equals or greater
than the envelope dimension.public boolean isEmpty()
AbstractEnvelope.isAllNaN()
always returns
false
for a non-empty envelope, but the converse is not always true.isEmpty
in class AbstractEnvelope
true
if this envelope is empty.DefaultGeographicBoundingBox.isEmpty()
,
RectangularShape.isEmpty()
public boolean isAllNaN()
false
if at least one ordinate value is not NaN.
This isAllNaN()
check is a little bit different than the AbstractEnvelope.isEmpty()
check
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:
isAllNaN() == true
, then isEmpty() == true
isEmpty() == false
, then isAllNaN() == false
isAllNaN
in class AbstractEnvelope
true
if this envelope has NaN values.GeneralEnvelope.setToNaN()
,
DefaultGeographicBoundingBox.isEmpty()
public int hashCode()
hashCode
in class AbstractEnvelope
public boolean equals(Object object)
true
if the specified object is an envelope of the same class
with equals coordinates and CRS.
Note:
This implementation requires that the provided object
argument
is of the same class than this envelope. We do not relax this rule since not every
implementations in the SIS code base follow the same contract.
equals
in class AbstractEnvelope
object
- The object to compare with this envelope.true
if the given object is equal to this envelope.public String toString()
BOX
" element.
The output is of the form "BOX
nD(
lower corner,
upper corner)
"
where n is the number of dimensions.
The number of dimension is written only if different than 2.
Example:
BOX(-90 -180, 90 180) BOX3D(-90 -180 0, 90 180 1)
Note:
The BOX
element is not part of the standard Well Known Text
(WKT) format. However it is understood by many softwares, for example GDAL and PostGIS.
The string returned by this method can be parsed
by the GeneralEnvelope
constructor.toString
in class AbstractEnvelope
BOX
or BOX3D
(most typical dimensions) element.Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.