org.geotools.geometry
Class TransformedDirectPosition

Object
  extended by AbstractDirectPosition
      extended by GeneralDirectPosition
          extended by TransformedDirectPosition
All Implemented Interfaces:
Serializable, Cloneable, Position, DirectPosition

public class TransformedDirectPosition
extends GeneralDirectPosition

A direct position capable to transform a point between an arbitrary CRS and its own CRS. This class caches the last transform used in order to improve the performances when the source and target CRS don't change often. Using this class is faster than invoking CoordinateOperationFactory.createOperation(sourceCRS, targetCRS) for every points.

This class usually don't appears in a public API. It is more typicaly used as a helper private field in some more complex class. For example suppose that MyClass needs to perform its internal working in some particular CRS, but we want robust API that adjusts itself to whatever CRS the client happen to use. MyClass could be written as below:
 public class MyClass {
     private static final CoordinateReferenceSystem   PUBLIC_CRS = ...
     private static final CoordinateReferenceSystem INTERNAL_CRS = ...

     private final TransformedDirectPosition myPosition =
             new TransformedDirectPosition(PUBLIC_CRS, INTERNAL_CRS, null);

     public void setPosition(DirectPosition position) throws TransformException {
         // The position CRS is usually PUBLIC_CRS, but code below will work even if it is not.
         myPosition.transform(position);
     }

     public DirectPosition getPosition() throws TransformException {
         return myPosition.inverseTransform(PUBLIC_CRS);
     }
 }
 

Since:
2.2
Author:
Martin Desruisseaux (IRD)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class GeneralDirectPosition
ordinates
 
Constructor Summary
TransformedDirectPosition()
          Creates a new direct position initialized with the WGS84 CRS.
TransformedDirectPosition(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, Hints hints)
          Creates a new position which will contains the result of coordinate transformations from sourceCRS to targetCRS.
 
Method Summary
 DirectPosition inverseTransform()
          Returns a new point with the same coordinates than this one, but transformed in the sourceCRS given at construction time.
 DirectPosition inverseTransform(CoordinateReferenceSystem crs)
          Returns a new point with the same coordinates than this one, but transformed in the given CRS.
 void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
          Sets the coordinate reference system in which the coordinate is given.
 void transform(DirectPosition position)
          Transforms a given position and stores the result in this object.
 
Methods inherited from class GeneralDirectPosition
clone, getCoordinate, getCoordinateReferenceSystem, getDimension, getOrdinate, hashCode, setLocation, setLocation, setLocation, setOrdinate, toPoint2D
 
Methods inherited from class AbstractDirectPosition
equals, getDirectPosition, setPosition, toString
 
Methods inherited from class Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransformedDirectPosition

public TransformedDirectPosition()
Creates a new direct position initialized with the WGS84 CRS.

Since:
2.3

TransformedDirectPosition

public TransformedDirectPosition(CoordinateReferenceSystem sourceCRS,
                                 CoordinateReferenceSystem targetCRS,
                                 Hints hints)
                          throws FactoryRegistryException
Creates a new position which will contains the result of coordinate transformations from sourceCRS to targetCRS. The CRS associated with this position will be initially set to targetCRS.

Parameters:
sourceCRS - The default CRS to be used by the transform(position) method only when the user-supplied position has a null associated CRS. This sourceCRS argument may be null, in which case it is assumed the same than targetCRS.
targetCRS - The CRS associated with this position. Used for every coordinate transformations until the next call to setCoordinateReferenceSystem or setLocation. This argument can not be null.
hints - The set of hints to use for fetching a CoordinateOperationFactory, or null if none.
Throws:
IllegalArgumentException - if targetCRS was null.
FactoryRegistryException - if no coordinate operation factory can be found for the specified hints.
Since:
2.3
Method Detail

setCoordinateReferenceSystem

public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
                                  throws MismatchedDimensionException
Sets the coordinate reference system in which the coordinate is given. The given CRS will be used as:

Overrides:
setCoordinateReferenceSystem in class GeneralDirectPosition
Parameters:
crs - The new CRS for this direct position.
Throws:
MismatchedDimensionException - if the specified CRS doesn't have the expected number of dimensions.

transform

public void transform(DirectPosition position)
               throws TransformException
Transforms a given position and stores the result in this object.

Parameters:
position - A position using an arbitrary CRS. This object will not be modified.
Throws:
TransformException - if a coordinate transformation was required and failed.

inverseTransform

public DirectPosition inverseTransform(CoordinateReferenceSystem crs)
                                throws TransformException
Returns a new point with the same coordinates than this one, but transformed in the given CRS. This method never returns this, so the returned point usually doesn't need to be cloned.

Parameters:
crs - The CRS for the position to be returned.
Returns:
The same position than this, but transformed in the specified CRS.
Throws:
TransformException - if a coordinate transformation was required and failed.
Since:
2.3

inverseTransform

public DirectPosition inverseTransform()
                                throws TransformException
Returns a new point with the same coordinates than this one, but transformed in the sourceCRS given at construction time. This method never returns this, so the returned point usually doesn't need to be cloned.

Returns:
The same position than this, but transformed in the source CRS.
Throws:
TransformException - if a coordinate transformation was required and failed.
Since:
2.3


Copyright © 1996-2014 Geotools. All Rights Reserved.