Class SimpleDirectPosition

Object
SimpleDirectPosition
All Implemented Interfaces:
Position, DirectPosition

public class SimpleDirectPosition extends Object implements DirectPosition
A DirectPosition implementation which store coordinate values in a double[] array. This implementation can store an optional reference to an existing Coordinate Reference System.
Since:
3.1
  • Field Details

    • coordinates

      public final double[] coordinates
      The coordinate values. The length of this array is the dimension of this direct position.

      This array is public for allowing more efficient coordinates operations, for example using the Arrays methods. However, we encourage to use only the methods from the DirectPosition interface in most cases.

      See Also:
    • crs

      The coordinate reference system associated to this direct position, or null if unspecified.

      The SimpleDirectPosition class does not provide any setter for this field, since uncontrolled modifications of geometry CRS is often undesirable. The decision to allow modifications or not is left to subclasses.

      See Also:
  • Constructor Details

    • SimpleDirectPosition

      public SimpleDirectPosition(int dimension)
      Creates a new direct position of the given dimension. The Coordinate Reference System is left unspecified. All coordinate values are initialized to zero.
      Parameters:
      dimension - the dimension.
    • SimpleDirectPosition

      public SimpleDirectPosition(CoordinateReferenceSystem crs)
      Creates a new direct position associated to the given coordinate reference system. The dimension of the new direct position is the dimension of the given CRS. All coordinate values are initialized to zero.
      Parameters:
      crs - the coordinate reference system to associate to the new direct position.
    • SimpleDirectPosition

      public SimpleDirectPosition(CoordinateReferenceSystem crs, double... coordinates) throws MismatchedDimensionException
      Creates a new direct position initialized to the given coordinate values. If the given CRS is non-null, then its dimension shall be equal to the length of the given coordinates array.

      This constructor assigns the given array directly (without clone) to the coordinates field, because that field is public anyway. Defensive copy would not protect the state of this object.

      Parameters:
      crs - the coordinate reference system, or null.
      coordinates - the coordinate values. This array is not cloned.
      Throws:
      MismatchedDimensionException - if the given CRS is not null and its dimension is not equals to the length of the coordinates array.
    • SimpleDirectPosition

      public SimpleDirectPosition(DirectPosition position)
      Creates a new direct position initialized to the CRS and coordinate values of the given direct position. This is a copy constructor.
      Parameters:
      position - the direct position from which to copy the CRS and coordinate values.
  • Method Details

    • getCoordinateReferenceSystem

      public CoordinateReferenceSystem getCoordinateReferenceSystem()
      Returns the coordinate reference system in which the coordinate is given. May be null if no CRS were specified at construction time. In such case, this particular direct position is assumed included in a larger object with such a reference to a coordinate reference system.
      Specified by:
      getCoordinateReferenceSystem in interface DirectPosition
      Returns:
      the coordinate reference system, or null.
    • getDimension

      public int getDimension()
      The length of coordinate sequence (the number of entries).
      Specified by:
      getDimension in interface DirectPosition
      Returns:
      the length of the coordinates array.
    • getCoordinate

      public double[] getCoordinate()
      Returns a copy of the coordinates array.
      Specified by:
      getCoordinate in interface DirectPosition
      Returns:
      a clone of the coordinates array.
    • getOrdinate

      public double getOrdinate(int dimension) throws IndexOutOfBoundsException
      Returns the coordinate at the specified dimension.
      Specified by:
      getOrdinate in interface DirectPosition
      Parameters:
      dimension - the dimension in the range 0 to dimension-1.
      Returns:
      the value in the coordinates array at the given index.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or is equal or greater than the position dimension.
    • setOrdinate

      public void setOrdinate(int dimension, double value) throws IndexOutOfBoundsException
      Sets the coordinate value along the specified dimension.
      Specified by:
      setOrdinate in interface DirectPosition
      Parameters:
      dimension - the dimension for the coordinate of interest.
      value - the coordinate value of interest.
      Throws:
      IndexOutOfBoundsException - if the given index is negative or is equal or greater than the position dimension.
    • getDirectPosition

      public DirectPosition getDirectPosition()
      Unconditionally returns this, since this object is already a direct position.
      Specified by:
      getDirectPosition in interface Position
      Returns:
      the direct position (may be this).
    • equals

      public boolean equals(Object object)
      Returns true if the specified object is also a DirectPosition with equal coordinate and equal CRS. This method performs the comparison as documented in the DirectPosition.equals(Object) Javadoc. In particular, the given object is not required to be of the same implementation class. Consequently, it should be possible to mix different DirectPosition implementations in the same hash map.
      Specified by:
      equals in interface DirectPosition
      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare with this direct position for equality.
      Returns:
      true if the given object is equal to this direct position.
    • hashCode

      public int hashCode()
      Returns a hash code value for this direct position. This method returns a value compliant with the contract documented in the DirectPosition.hashCode() javadoc. Consequently, it should be possible to mix different DirectPosition implementations in the same hash map.
      Specified by:
      hashCode in interface DirectPosition
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this position.
    • toString

      public String toString()
      Returns a string representation of this direct position in Well-Known Text (WKT) format.
      Overrides:
      toString in class Object
      Returns:
      the Well-Known Text representation of this direct position.
      See Also: