org.geotools.geometry
Class DirectPosition2D

java.lang.Object
  extended byjava.awt.geom.Point2D
      extended byjava.awt.geom.Point2D.Double
          extended byorg.geotools.geometry.DirectPosition2D
All Implemented Interfaces:
java.lang.Cloneable, org.opengis.util.Cloneable, org.opengis.spatialschema.geometry.DirectPosition, org.opengis.spatialschema.geometry.geometry.Position, java.io.Serializable

public class DirectPosition2D
extends java.awt.geom.Point2D.Double
implements org.opengis.spatialschema.geometry.DirectPosition, java.io.Serializable

Holds the coordinates for a two-dimensional position within some coordinate reference system.

Note: This class inherits x and y fields. But despite their names, they don't need to be oriented toward East and North respectively. The (x,y) axis can have any orientation and should be understood as "ordinate 0" and "ordinate 1" values instead. This is not specific to this implementation; in Java2D too, the visual axis orientation depend on the affine transform in the graphics context.

The rational for avoiding axis orientation restriction is that other DirectPosition implementation do not have such restriction, and anyway it would be hard to generalize (what to do with North-East direction?).

Since:
2.0
Version:
$Id: DirectPosition2D.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Point2D
java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float
 
Field Summary
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Constructor Summary
DirectPosition2D()
          Constructs a position initialized to (0,0) with a coordinate reference system.
DirectPosition2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
          Constructs a position with the specified coordinate reference system.
DirectPosition2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs, double x, double y)
          Constructs a 2D position from the specified ordinates in the specified CRS.
DirectPosition2D(org.opengis.spatialschema.geometry.DirectPosition point)
          Constructs a position initialized to the same values than the specified point.
DirectPosition2D(double x, double y)
          Constructs a 2D position from the specified ordinates.
DirectPosition2D(java.awt.geom.Point2D point)
          Constructs a position from the specified Point2D.
 
Method Summary
 org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
          Returns the coordinate reference system in which the coordinate is given.
 double[] getCoordinates()
          Returns a sequence of numbers that hold the coordinate of this position in its reference system.
 int getDimension()
          The length of coordinate sequence (the number of entries).
 double getOrdinate(int dimension)
          Returns the ordinate at the specified dimension.
 org.opengis.spatialschema.geometry.DirectPosition getPosition()
          Returns always this, the direct position for this position.
 int hashCode()
          Returns a hash value for this coordinate.
 void setCoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
          Set the coordinate reference system in which the coordinate is given.
 void setLocation(org.opengis.spatialschema.geometry.DirectPosition position)
          Set this coordinate to the specified direct position.
 void setOrdinate(int dimension, double value)
          Sets the ordinate value along the specified dimension.
 java.awt.geom.Point2D toPoint2D()
          Returns a Point2D with the same coordinate as this direct position.
 java.lang.String toString()
          Returns a string representation of this coordinate.
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY, setLocation
 
Methods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opengis.spatialschema.geometry.DirectPosition
clone
 

Constructor Detail

DirectPosition2D

public DirectPosition2D()
Constructs a position initialized to (0,0) with a coordinate reference system.


DirectPosition2D

public DirectPosition2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Constructs a position with the specified coordinate reference system.


DirectPosition2D

public DirectPosition2D(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.


DirectPosition2D

public DirectPosition2D(org.opengis.referencing.crs.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.


DirectPosition2D

public DirectPosition2D(java.awt.geom.Point2D point)
Constructs a position from the specified Point2D.


DirectPosition2D

public DirectPosition2D(org.opengis.spatialschema.geometry.DirectPosition point)
Constructs a position initialized to the same values than the specified point.

Method Detail

getPosition

public org.opengis.spatialschema.geometry.DirectPosition getPosition()
Returns always this, the direct position for this position.

Specified by:
getPosition in interface org.opengis.spatialschema.geometry.geometry.Position

getCoordinateReferenceSystem

public final org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()
Returns the coordinate reference system in which the coordinate is given. May be if this particular is included in a larger object with such a reference to a coordinate reference system.

Specified by:
getCoordinateReferenceSystem in interface org.opengis.spatialschema.geometry.DirectPosition
Returns:
The coordinate reference system, or .

setCoordinateReferenceSystem

public void setCoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Set the coordinate reference system in which the coordinate is given.

Parameters:
crs - The new coordinate reference system, or .

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 org.opengis.spatialschema.geometry.DirectPosition
Returns:
The dimensionality of this position.

getCoordinates

public double[] getCoordinates()
Returns a sequence of numbers that hold the coordinate of this position in its reference system.

Specified by:
getCoordinates in interface org.opengis.spatialschema.geometry.DirectPosition
Returns:
The coordinates

getOrdinate

public final double getOrdinate(int dimension)
                         throws java.lang.IndexOutOfBoundsException
Returns the ordinate at the specified dimension.

Specified by:
getOrdinate in interface org.opengis.spatialschema.geometry.DirectPosition
Parameters:
dimension - The dimension in the range 0 to 1 inclusive.
Returns:
The coordinate at the specified dimension.
Throws:
java.lang.IndexOutOfBoundsException - if the specified dimension is out of bounds.
To Do:
Provides a more detailled error message.

setOrdinate

public final void setOrdinate(int dimension,
                              double value)
                       throws java.lang.IndexOutOfBoundsException
Sets the ordinate value along the specified dimension.

Specified by:
setOrdinate in interface org.opengis.spatialschema.geometry.DirectPosition
Parameters:
dimension - the dimension for the ordinate of interest.
value - the ordinate value of interest.
Throws:
java.lang.IndexOutOfBoundsException - if the specified dimension is out of bounds.
To Do:
Provides a more detailled error message.

setLocation

public void setLocation(org.opengis.spatialschema.geometry.DirectPosition position)
                 throws org.opengis.spatialschema.geometry.MismatchedDimensionException
Set this coordinate to the specified direct position. If the specified position contains a coordinate reference system, then the CRS for this position will be set to the CRS of the specified position.

Parameters:
position - The new position for this point.
Throws:
org.opengis.spatialschema.geometry.MismatchedDimensionException - if this point doesn't have the expected dimension.

toPoint2D

public java.awt.geom.Point2D toPoint2D()
Returns a Point2D with the same coordinate as this direct position.


toString

public java.lang.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.


hashCode

public int hashCode()
Returns a hash value for this coordinate. This value need not remain consistent between different implementations of the same class.



Copyright © GeoTools. All Rights Reserved.