org.geotools.geometry
Class GeneralDirectPosition

java.lang.Object
  extended byorg.geotools.geometry.GeneralDirectPosition
All Implemented Interfaces:
org.opengis.util.Cloneable, java.lang.Cloneable, org.opengis.spatialschema.geometry.DirectPosition, org.opengis.spatialschema.geometry.geometry.Position, java.io.Serializable

public final class GeneralDirectPosition
extends java.lang.Object
implements org.opengis.spatialschema.geometry.DirectPosition, java.io.Serializable

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 CoordinateReferenceSystem, 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 CoordinateReferenceSystem.

This particular implementation of DirectPosition is said "General" because it uses an array of ordinates of an arbitrary length. If the direct position is know to be always two-dimensional, then DirectPosition2D may provides a more efficient implementation.

Version:
$Id$
Author:
Martin Desruisseaux
See Also:
Point2D, Serialized Form

Field Summary
 double[] ordinates
          The ordinates of the direct position.
 
Constructor Summary
GeneralDirectPosition(double[] ordinates)
          Construct a position with the specified ordinates.
GeneralDirectPosition(double x, double y)
          Construct a 2D position from the specified ordinates.
GeneralDirectPosition(double x, double y, double z)
          Construct a 3D position from the specified ordinates.
GeneralDirectPosition(GeneralDirectPosition point)
          Construct a position initialized to the same values than the specified point.
GeneralDirectPosition(int numDim)
          Construct a position with the specified number of dimensions.
GeneralDirectPosition(java.awt.geom.Point2D point)
          Construct a position from the specified Point2D.
 
Method Summary
 java.lang.Object clone()
          Returns a deep copy of this position.
 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(GeneralDirectPosition position)
          Set this coordinate to the specified direct position.
 void setLocation(java.awt.geom.Point2D point)
          Set this coordinate to the specified Point2D.
 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.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ordinates

public final double[] ordinates
The ordinates of the direct position.

Constructor Detail

GeneralDirectPosition

public GeneralDirectPosition(int numDim)
                      throws java.lang.NegativeArraySizeException
Construct a position with the specified number of dimensions.

Parameters:
numDim - Number of dimensions.
Throws:
java.lang.NegativeArraySizeException - if numDim is negative.

GeneralDirectPosition

public GeneralDirectPosition(double[] ordinates)
Construct a position with the specified ordinates. The ordinates array will be copied.


GeneralDirectPosition

public GeneralDirectPosition(double x,
                             double y)
Construct a 2D position from the specified ordinates.


GeneralDirectPosition

public GeneralDirectPosition(double x,
                             double y,
                             double z)
Construct a 3D position from the specified ordinates.


GeneralDirectPosition

public GeneralDirectPosition(java.awt.geom.Point2D point)
Construct a position from the specified Point2D.


GeneralDirectPosition

public GeneralDirectPosition(GeneralDirectPosition point)
Construct 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 null if this particular DirectPosition 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 null.

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 null.

getDimension

public final int getDimension()
The length of coordinate sequence (the number of entries). This may be less than or equal to the dimensionality of the coordinate reference system.

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 dimension-1.
Returns:
The coordinate at the specified dimension.
Throws:
java.lang.IndexOutOfBoundsException - if the specified dimension is out of bounds.

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.

setLocation

public void setLocation(GeneralDirectPosition 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.

setLocation

public void setLocation(java.awt.geom.Point2D point)
                 throws org.opengis.spatialschema.geometry.MismatchedDimensionException
Set this coordinate to the specified Point2D. This coordinate must be two-dimensional.

Parameters:
point - The new coordinate for this point.
Throws:
org.opengis.spatialschema.geometry.MismatchedDimensionException - if this coordinate point is not two-dimensional.
To Do:
Check axis order.

toPoint2D

public java.awt.geom.Point2D toPoint2D()
                                throws java.lang.IllegalStateException
Returns a Point2D with the same coordinate as this direct position. This is a convenience method for interoperability with Java2D.

Throws:
java.lang.IllegalStateException - if this coordinate point is not two-dimensional.
To Do:
Check axis order.

toString

public java.lang.String toString()
Returns a string representation of this coordinate. The returned string is implementation dependent. It is usually provided for debugging purposes.


hashCode

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


clone

public java.lang.Object clone()
Returns a deep copy of this position.

Specified by:
clone in interface org.opengis.spatialschema.geometry.DirectPosition


Copyright © GeoTools. All Rights Reserved.