Interface Position

  • All Known Implementing Classes:
    AbstractPosition, GeneralPosition, Position1D, Position2D, Position3D, TransformedPosition

    public interface Position
    Holds the coordinates for a position within some coordinate reference system. Since DirectPositions, as data types, will often be included in larger objects (such as geometries) that have references to coordinate reference system, the getCoordinateReferenceSystem() method may returns null if this particular DirectPosition is included in a larger object with such a reference to a coordinate reference system. In this case, the cordinate reference system is implicitly assumed to take on the value of the containing object's coordinate reference system.

    Note: this interface does not extends Cloneable on purpose, since DirectPosition implementations are most likely to be backed by references to internal structures of the geometry containing this position. A direct position may or may not be cloneable at implementor choice.

    GeoAPI 1.0
    Martin Desruisseaux (IRD)
    • Method Detail

      • getDimension

        int getDimension()
        The length of coordinate sequence (the number of entries). This is determined by the coordinate reference system.
        The dimensionality of this position.
      • getCoordinate

        double[] getCoordinate()
        A copy of the ordinates presented as an array of double values. Please note that this is only a copy (the real values may be stored in another format) so changes to the returned array will not affect the source DirectPosition.
         final int dim = position.getDimension();
         for (int i=0; i<dim; i++) {
             position.getOrdinate(i); // no copy overhead
        To manipulate ordinates, the following idiom can be used:
         position.setOrdinate(i, value); // edit in place
        There are a couple reasons for requerying a copy:

        • We want an array of coordinates with the intend to modify it for computation purpose (without modifying the original DirectPosition), or we want to protect the array from future DirectPosition changes.
        • If DirectPosition.getOrdinates() is garanteed to not return the backing array, then we can work directly on this array. If we don't have this garantee, then we must conservatively clone the array in every cases.
        • Cloning the returned array is useless if the implementation cloned the array or was forced to returns a new array anyway (for example because the coordinates were computed on the fly)

        Precedence is given to data integrity over getOrdinates() performance. Performance concern can be avoided with usage of getOrdinate(int).

        A copy of the coordinates. Changes in the returned array will not be reflected back in this DirectPosition object.
      • getDirectPosition

        Position getDirectPosition()
        Returns the direct position. This method shall never returns null, but may returns this if invoked on an object which is already a DirectPosition instance.
        The direct position (may be this).
        GeoAPI 2.2
      • equals

        boolean equals​(Object object)
        Compares this direct position with the specified object for equality. Two direct positions are considered equal if the following conditions are meet:

        equals in class Object
        object - The object to compare with this direct position for equality.
        true if the given object is equals to this direct position.
        GeoAPI 2.1
      • hashCode

        int hashCode()
        Returns a hash code value for this direct position. This method should returns the same value as: {@linkplain java.util.Arrays.hashCode(double[]) Arrays.hashCode}(getCoordinate()) + getCoordinateReferenceSystem().hashCode() where the right hand side of the addition is omitted if the coordinate reference system is null.
        hashCode in class Object
        A hash code value for this direct position.
        GeoAPI 2.1