Package org.opengis.example.geometry
Class SimpleEnvelope
- Object
-
- SimpleEnvelope
-
- All Implemented Interfaces:
Serializable
,Envelope
public class SimpleEnvelope extends Object implements Envelope, Serializable
An unmodifiableEnvelope
implementation defined by two corners. This implementation can store an optional reference to an existing Coordinate Reference System.This simple implementation does not support envelopes crossing the anti-meridian. Consequently, lower ordinate values shall not be greater than corresponding upper ordinate values.
- Since:
- 3.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SimpleEnvelope(DirectPosition lowerCorner, DirectPosition upperCorner)
Constructs an envelope defined by two direct positions.SimpleEnvelope(Envelope envelope)
Constructs a new envelope with the same data than the specified envelope.
-
Method Summary
Modifier and Type Method Description boolean
equals(Object object)
Compares this envelope with the specified object for equality.CoordinateReferenceSystem
getCoordinateReferenceSystem()
Returns the envelope coordinate reference system, ornull
if unknown.int
getDimension()
Returns the length of coordinate sequence (the number of entries) in this envelope.DirectPosition
getLowerCorner()
The limits in the direction of decreasing ordinate values for each 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.DirectPosition
getUpperCorner()
The limits in the direction of increasing ordinate values for each dimension.int
hashCode()
Returns an arbitrary hash code value for this envelope.String
toString()
Formats this envelope in the Well-Known Text (WKT) format.
-
-
-
Constructor Detail
-
SimpleEnvelope
public SimpleEnvelope(DirectPosition lowerCorner, DirectPosition upperCorner) throws MismatchedDimensionException, MismatchedReferenceSystemException
Constructs an envelope defined by two direct positions. The CRS of the envelope will be the CRS of the given direct positions, which shall be the equal.- Parameters:
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.- Throws:
MismatchedReferenceSystemException
- if the CRS of the two position are not equal.MismatchedDimensionException
- if the two positions do not have the same dimension.IllegalArgumentException
- if an ordinate value in the lower corner is greater than the corresponding ordinate value in the upper corner.
-
SimpleEnvelope
public SimpleEnvelope(Envelope envelope)
Constructs a new envelope with the same data than the specified envelope. This is a copy constructor.- Parameters:
envelope
- the envelope to copy.- Throws:
IllegalArgumentException
- if an ordinate value in the lower corner is greater than the corresponding ordinate value in the upper corner.
-
-
Method Detail
-
getDimension
public final int getDimension()
Returns the length of coordinate sequence (the number of entries) in this envelope.- Specified by:
getDimension
in interfaceEnvelope
- Returns:
- the dimensionality of this envelope.
-
getCoordinateReferenceSystem
public CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the envelope coordinate reference system, ornull
if unknown.- Specified by:
getCoordinateReferenceSystem
in interfaceEnvelope
- Returns:
- the envelope CRS, or
null
if unknown.
-
getLowerCorner
public DirectPosition getLowerCorner()
The limits in the direction of decreasing ordinate values for each dimension. This is typically a coordinate position consisting of all the minimal ordinates for each dimension for all points within theEnvelope
.This method returns a copy of the lower corner. Changes in the returned position will not be reflected in this envelope.
- Specified by:
getLowerCorner
in interfaceEnvelope
- Returns:
- the lower corner, typically (but not necessarily) containing minimal ordinate values.
-
getUpperCorner
public DirectPosition getUpperCorner()
The limits in the direction of increasing ordinate values for each dimension. This is typically a coordinate position consisting of all the maximal ordinates for each dimension for all points within theEnvelope
.This method returns a copy of the upper corner. Changes in the returned position will not be reflected in this envelope.
- Specified by:
getUpperCorner
in interfaceEnvelope
- Returns:
- the upper corner, typically (but not necessarily) containing maximal ordinate values.
-
getMinimum
public double getMinimum(int dimension) throws IndexOutOfBoundsException
Returns the minimal ordinate value for the specified dimension. Since this simple class does not support envelopes crossing the anti-meridian, this method is equivalent to the following code:return getLowerCorner().getOrdinate(dimension);
- Specified by:
getMinimum
in interfaceEnvelope
- Parameters:
dimension
- the dimension for which to obtain the ordinate value.- Returns:
- the minimal ordinate at the given dimension.
- Throws:
IndexOutOfBoundsException
- if the given index is negative or is equals or greater than the envelope dimension.
-
getMaximum
public double getMaximum(int dimension) throws IndexOutOfBoundsException
Returns the maximal ordinate value for the specified dimension. Since this simple class does not support envelopes crossing the anti-meridian, this method is equivalent to the following code:return getUpperCorner().getOrdinate(dimension);
- Specified by:
getMaximum
in interfaceEnvelope
- Parameters:
dimension
- the dimension for which to obtain the ordinate value.- Returns:
- the maximal ordinate at the given dimension.
- Throws:
IndexOutOfBoundsException
- if the given index is negative or is equals or greater than the envelope dimension.
-
getMedian
public double getMedian(int dimension) throws IndexOutOfBoundsException
Returns the median ordinate along the specified dimension. Since this simple class does not support envelopes crossing the anti-meridian, this method is equivalent to the following code:return 0.5*(getMinimum(dimension) + getMaximum(dimension));
- Specified by:
getMedian
in interfaceEnvelope
- Throws:
IndexOutOfBoundsException
-
getSpan
public double getSpan(int dimension) throws IndexOutOfBoundsException
Returns the envelope span (typically width or height) along the specified dimension. Since this simple class does not support envelopes crossing the anti-meridian, this method is equivalent to the following code:return getMaximum(dimension) - getMinimum(dimension);
- Specified by:
getSpan
in interfaceEnvelope
- Throws:
IndexOutOfBoundsException
-
equals
public boolean equals(Object object)
Compares this envelope with the specified object for equality. Since theequals(Object)
andhashCode()
methods are not documented in theEnvelope
interface, this method returnsfalse
if the given object is not an instance of the sameSimpleEnvelope
class. We do that in order to preserve consistency withhashCode()
.
-
hashCode
public int hashCode()
Returns an arbitrary hash code value for this envelope.
-
toString
public String toString()
Formats this envelope in the Well-Known Text (WKT) format. The output is of the form "BOX
nD(
lower corner,
upper corner)
" where n is the number of dimensions.
-
-