Class Position2D

    • Constructor Detail

      • Position2D

        public Position2D()
        Constructs a position initialized to (0,0) with a null coordinate reference system.
      • Position2D

        public Position2D​(CoordinateReferenceSystem crs)
        Constructs a position with the specified coordinate reference system.
        Parameters:
        crs - The coordinate reference system, or null.
      • Position2D

        public Position2D​(double x,
                          double y)
        Constructs a 2D position from the specified ordinates. Despite their name, the (x,y) coordinates don't need to be oriented toward (East, North). Those parameter names simply match the x and y fields. See the class javadoc for details.
        Parameters:
        x - The x value.
        y - The y value.
      • Position2D

        public Position2D​(CoordinateReferenceSystem crs,
                          double x,
                          double y)
        Constructs a 2D position from the specified ordinates in the specified CRS. Despite their name, the (x,y) coordinates don't need to be oriented toward (East, North). Those parameter names simply match the x and y fields. The actual axis orientations are determined by the specified CRS. See the class javadoc for details.
        Parameters:
        crs - The coordinate reference system, or null.
        x - The x value.
        y - The y value.
      • Position2D

        public Position2D​(Point2D point)
        Constructs a position from the specified Point2D.
        Parameters:
        point - The point to copy.
      • Position2D

        public Position2D​(Position point)
        Constructs a position initialized to the same values than the specified point.
        Parameters:
        point - The point to copy.
    • Method Detail

      • getDirectPosition

        public Position getDirectPosition()
        Returns always this, the direct position for this position.
        Specified by:
        getDirectPosition in interface Position
        Returns:
        The direct position (may be this).
        Since:
        2.5
      • setCoordinateReferenceSystem

        public void setCoordinateReferenceSystem​(CoordinateReferenceSystem crs)
        Set the coordinate reference system in which the coordinate is given.
        Parameters:
        crs - The new coordinate reference system, or null.
      • getDimension

        public final int getDimension()
        The length of coordinate sequence (the number of entries). This is always 2 for DirectPosition2D objects.
        Specified by:
        getDimension in interface Position
        Returns:
        The dimensionality of this position.
      • getCoordinate

        public double[] getCoordinate()
        Returns a sequence of numbers that hold the coordinate of this position in its reference system.
        Specified by:
        getCoordinate in interface Position
        Returns:
        The coordinates
      • getOrdinate

        public final double getOrdinate​(int dimension)
                                 throws IndexOutOfBoundsException
        Returns the ordinate at the specified dimension.
        Specified by:
        getOrdinate in interface Position
        Parameters:
        dimension - The dimension in the range 0 to 1 inclusive.
        Returns:
        The coordinate at the specified dimension.
        Throws:
        IndexOutOfBoundsException - if the specified dimension is out of bounds.
      • setOrdinate

        public final void setOrdinate​(int dimension,
                                      double value)
                               throws IndexOutOfBoundsException
        Sets the ordinate value along the specified dimension.
        Specified by:
        setOrdinate in interface Position
        Parameters:
        dimension - the dimension for the ordinate of interest.
        value - the ordinate value of interest.
        Throws:
        IndexOutOfBoundsException - if the specified dimension is out of bounds.
      • toPoint2D

        public Point2D toPoint2D()
        Returns a Point2D with the same coordinate as this direct position.
        Returns:
        This position as a point.
      • toString

        public String toString()
        Returns a string representation of this coordinate. The default implementation formats this coordinate using a shared instance of CoordinateFormat. This is okay for occasional formatting (for example for debugging purpose). But if there is a lot of positions to format, users will get better performance and more control by using their own instance of CoordinateFormat.
        Overrides:
        toString in class Point2D.Double
      • equals

        public boolean equals​(Object object)
        Compares this point with the specified object for equality. If the given object implements the Position interface, then the comparaison is performed as specified in its Position.equals(java.lang.Object) contract. Otherwise the comparaison is performed as specified in Point2D.equals(java.lang.Object).
        Specified by:
        equals in interface Position
        Overrides:
        equals in class Point2D
        Parameters:
        object - The object to compare with this position.
        Returns:
        true if the given object is equals to this position.