Package org.opengis.example.geometry
Class SimpleEnvelope
- Object
-
- SimpleEnvelope
-
- All Implemented Interfaces:
Serializable,Envelope
public class SimpleEnvelope extends Object implements Envelope, Serializable
An unmodifiableEnvelopeimplementation 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 booleanequals(Object object)Compares this envelope with the specified object for equality.CoordinateReferenceSystemgetCoordinateReferenceSystem()Returns the envelope coordinate reference system, ornullif unknown.intgetDimension()Returns the length of coordinate sequence (the number of entries) in this envelope.DirectPositiongetLowerCorner()The limits in the direction of decreasing ordinate values for each dimension.doublegetMaximum(int dimension)Returns the maximal ordinate value for the specified dimension.doublegetMedian(int dimension)Returns the median ordinate along the specified dimension.doublegetMinimum(int dimension)Returns the minimal ordinate value for the specified dimension.doublegetSpan(int dimension)Returns the envelope span (typically width or height) along the specified dimension.DirectPositiongetUpperCorner()The limits in the direction of increasing ordinate values for each dimension.inthashCode()Returns an arbitrary hash code value for this envelope.StringtoString()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:
getDimensionin interfaceEnvelope- Returns:
- the dimensionality of this envelope.
-
getCoordinateReferenceSystem
public CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the envelope coordinate reference system, ornullif unknown.- Specified by:
getCoordinateReferenceSystemin interfaceEnvelope- Returns:
- the envelope CRS, or
nullif 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:
getLowerCornerin 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:
getUpperCornerin interfaceEnvelope- Returns:
- the upper corner, typically (but not necessarily) containing maximal ordinate values.
-
getMinimum
public double getMinimum(int dimension) throws IndexOutOfBoundsExceptionReturns 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:
getMinimumin 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 IndexOutOfBoundsExceptionReturns 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:
getMaximumin 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 IndexOutOfBoundsExceptionReturns 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:
getMedianin interfaceEnvelope- Throws:
IndexOutOfBoundsException
-
getSpan
public double getSpan(int dimension) throws IndexOutOfBoundsExceptionReturns 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:
getSpanin 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 theEnvelopeinterface, this method returnsfalseif the given object is not an instance of the sameSimpleEnvelopeclass. 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 "BOXnD(lower corner,upper corner)" where n is the number of dimensions.
-
-