Class SimpleEnvelope

Object
SimpleEnvelope
All Implemented Interfaces:
Envelope

public class SimpleEnvelope extends Object implements Envelope
An unmodifiable Envelope 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 coordinate values shall not be greater than corresponding upper coordinate values.

Since:
3.1
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleEnvelope(DirectPosition lowerCorner, DirectPosition upperCorner)
    Constructs an envelope defined by two direct positions.
    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.
    Returns the envelope coordinate reference system, or null if unknown.
    final int
    Returns the length of coordinate sequence (the number of entries) in this envelope.
    The limits in the direction of decreasing coordinate values for each dimension.
    double
    getMaximum(int dimension)
    Returns the maximal coordinate value for the specified dimension.
    double
    getMedian(int dimension)
    Returns the median coordinate along the specified dimension.
    double
    getMinimum(int dimension)
    Returns the minimal coordinate value for the specified dimension.
    double
    getSpan(int dimension)
    Returns the envelope span (typically width or height) along the specified dimension.
    The limits in the direction of increasing coordinate values for each dimension.
    int
    Returns an arbitrary hash code value for this envelope.
    Formats this envelope in the Well-Known Text (WKT) format.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SimpleEnvelope

      public SimpleEnvelope(DirectPosition lowerCorner, DirectPosition upperCorner) throws MismatchedDimensionException
      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 coordinate values for each dimension.
      upperCorner - the limits in the direction of increasing coordinate values for each dimension.
      Throws:
      MismatchedDimensionException - if the two positions do not have the same dimension.
      IllegalArgumentException - if an coordinate value in the lower corner is greater than the corresponding coordinate 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 coordinate value in the lower corner is greater than the corresponding coordinate value in the upper corner.
  • Method Details

    • getDimension

      public final int getDimension()
      Returns the length of coordinate sequence (the number of entries) in this envelope.
      Specified by:
      getDimension in interface Envelope
      Returns:
      the dimensionality of this envelope.
    • getCoordinateReferenceSystem

      public CoordinateReferenceSystem getCoordinateReferenceSystem()
      Returns the envelope coordinate reference system, or null if unknown.
      Specified by:
      getCoordinateReferenceSystem in interface Envelope
      Returns:
      the envelope CRS, or null if unknown.
    • getLowerCorner

      public DirectPosition getLowerCorner()
      The limits in the direction of decreasing coordinate values for each dimension. This is typically a coordinate position consisting of all the minimal coordinates for each dimension for all points within the Envelope.

      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 interface Envelope
      Returns:
      the lower corner, typically (but not necessarily) containing minimal coordinate values.
    • getUpperCorner

      public DirectPosition getUpperCorner()
      The limits in the direction of increasing coordinate values for each dimension. This is typically a coordinate position consisting of all the maximal coordinates for each dimension for all points within the Envelope.

      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 interface Envelope
      Returns:
      the upper corner, typically (but not necessarily) containing maximal coordinate values.
    • getMinimum

      public double getMinimum(int dimension) throws IndexOutOfBoundsException
      Returns the minimal coordinate 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 interface Envelope
      Parameters:
      dimension - the dimension for which to obtain the coordinate value.
      Returns:
      the minimal coordinate at the given dimension.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or is equal or greater than the envelope dimension.
      See Also:
    • getMaximum

      public double getMaximum(int dimension) throws IndexOutOfBoundsException
      Returns the maximal coordinate 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 interface Envelope
      Parameters:
      dimension - the dimension for which to obtain the coordinate value.
      Returns:
      the maximal coordinate at the given dimension.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or is equal or greater than the envelope dimension.
      See Also:
    • getMedian

      public double getMedian(int dimension) throws IndexOutOfBoundsException
      Returns the median coordinate 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 interface Envelope
      Parameters:
      dimension - the dimension for which to obtain the coordinate value.
      Returns:
      the median coordinate at the given dimension.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or is equal or greater than the envelope dimension.
      See Also:
    • 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 interface Envelope
      Parameters:
      dimension - the dimension for which to obtain the span.
      Returns:
      the span (typically width or height) at the given dimension.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or is equal or greater than the envelope dimension.
      See Also:
    • equals

      public boolean equals(Object object)
      Compares this envelope with the specified object for equality. Since the equals(Object) and hashCode() methods are not documented in the Envelope interface, this method returns false if the given object is not an instance of the same SimpleEnvelope class. We do that in order to preserve consistency with hashCode().
      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare with this envelope, or null.
      Returns:
      true if the given object is an instance of the same SimpleEnvelope class, and have equal coordinate values and equal CRS.
    • hashCode

      public int hashCode()
      Returns an arbitrary hash code value for this envelope.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value.
    • 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.
      Overrides:
      toString in class Object
      Returns:
      this envelope as a BOX2D or BOX3D (most typical dimensions) in WKT format.