Class GeneralDirectPosition

    • Field Detail

      • coordinates

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

      • 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.
        Parameters:
        crs - the coordinate reference system to be given to this position.
      • 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 note: 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 later 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 than 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 can not be parsed.
        See Also:
        to­String(), Coordinate­Format
    • Method Detail

      • getDimension

        public final int getDimension()
        The length of coordinate sequence (the number of entries). This is always equals to the length of the coordinates array.
        Specified by:
        get­Dimension in interface Direct­Position
        Returns:
        the dimensionality of this position.
      • getCoordinateReferenceSystem

        public final CoordinateReferenceSystem getCoordinateReferenceSystem()
        Returns the coordinate reference system in which the coordinate is given. May be null if this particular Direct­Position is included in a larger object with such a reference to a CRS.
        Specified by:
        get­Coordinate­Reference­System in interface Direct­Position
        Returns:
        the coordinate reference system, or null.
      • setCoordinate

        public void setCoordinate​(double... coordinates)
                           throws MismatchedDimensionException
        Sets the coordinate values along all dimensions.
        Parameters:
        coordinates - the new coordinates values, or a null array for setting all coordinate values to Na­N.
        Throws:
        Mismatched­Dimension­Exception - if the length of the specified array is not equals to the dimension of this position.
      • toString

        public String toString()
        Formats this position in the Well Known Text (WKT) format. The returned string is like below, where x₀, x₁, x₂, etc. are the coordinate values at index 0, 1, 2, etc.:
        POINT(x₀ x₁ x₂ …)
        This method formats the numbers as with Double​.to­String(double) (i.e. without fixed number of fraction digits). The string returned by this method can be parsed by the General­Direct­Position constructor.
        Overrides:
        to­String in class Abstract­Direct­Position
        Returns:
        this position as a POINT in Well Known Text (WKT) format.
      • clone

        public GeneralDirectPosition clone()
        Returns a deep copy of this position.
        Overrides:
        clone in class Object
        Returns:
        a copy of this direct position.
      • equals

        public boolean equals​(Object object)
        Returns true if the specified object is also a Direct­Position with equal coordinates and equal CRS. This method performs the comparison as documented in the Direct­Position​.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 Direct­Position implementations in the same hash map.
        Specified by:
        equals in interface Direct­Position
        Overrides:
        equals in class Abstract­Direct­Position
        Parameters:
        object - the object to compare with this position.
        Returns:
        true if the given object is equal to this position.