Class GeneralDirectPosition

All Implemented Interfaces:
Serializable, Cloneable, Printable, Position, Direct­Position

public class GeneralDirectPosition extends AbstractDirectPosition implements Serializable, Cloneable
A mutable Direct­Position (the coordinates of a position) of arbitrary dimension. This particular implementation of Direct­Position is said "General" because it uses an array of coordinates of an arbitrary length. If the direct position is known to be always two-dimensional, then Direct­Position2D provides a more efficient implementation.

Coordinate Reference System (CRS) optionality

Since Direct­Positions, as data types, will often be included in larger objects (such as Geometry) that have references to Coordinate­Reference­System, the get­Coordinate­Reference­System() method may returns null if this particular Direct­Position is included in such larger object. In this case, the coordinate reference system is implicitly assumed to take on the value of the containing object's Coordinate­Reference­System.
Since:
0.3
See Also:
  • Field Details

    • coordinates

      public final double[] coordinates
      The coordinates of the direct position. The length of this array is the dimension of this direct position.
  • Constructor Details

    • GeneralDirectPosition

      public GeneralDirectPosition(CoordinateReferenceSystem crs)
      Constructs a position using the specified coordinate reference system. The number of dimensions is inferred from the coordinate reference system. All coordinate values are initialized to zero.
      Parameters:
      crs - the coordinate reference system to be given to this position.
    • GeneralDirectPosition

      public GeneralDirectPosition(int dimension) throws NegativeArraySizeException
      Constructs a position with the specified number of dimensions. All coordinate values are initialized to zero.
      Parameters:
      dimension - number of dimensions.
      Throws:
      Negative­Array­Size­Exception - if dimension is negative.
    • GeneralDirectPosition

      public GeneralDirectPosition(double... coordinates)
      Constructs a position with the specified coordinates. This constructor assigns the given array directly (without clone) to the coordinates field. Consequently, callers shall not recycle the same array for creating many instances.

      Implementation notes

      The array is not cloned because this is usually not needed, especially in the context of variable argument lengths since the array is often created implicitly. Furthermore, the coordinates field is public, so cloning the array would not protect the state of this object anyway.

      Caution: if only one number is specified, make sure that the number type is double, float or long otherwise the General­Direct­Position(int) constructor would be invoked with a very different meaning. For example, for creating a one-dimensional coordinate initialized to the coordinate value 100, use new General­Direct­Position(100.0), not new General­Direct­Position(100), because the latter would actually create a position with 100 dimensions.

      Parameters:
      coordinates - the coordinate values. This array is not cloned.
    • GeneralDirectPosition

      public GeneralDirectPosition(DirectPosition point)
      Constructs a position initialized to the same values as the specified point. This is a copy constructor.
      Parameters:
      point - the position to copy.
    • GeneralDirectPosition

      public GeneralDirectPosition(CharSequence wkt) throws IllegalArgumentException
      Constructs a position initialized to the values parsed from the given string in Well Known Text (WKT) format. The given string is typically a POINT element like below:
      POINT(6 10)
      
      However, this constructor is lenient to other types like POINT ZM.
      Parameters:
      wkt - the POINT or other kind of element to parse.
      Throws:
      Illegal­Argument­Exception - if the given string cannot be parsed.
      See Also:
  • Method Details