Class TransformedPosition
- Object
- 
- AbstractPosition
- 
- GeneralPosition
- 
- TransformedPosition
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- Cloneable,- Position,- Cloneable
 
 public class TransformedPosition extends GeneralPosition 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 invokingCoordinateOperationFactory.createOperation(sourceCRS, targetCRS)for every points.- 
       Note 1: This class is advantageous on a performance point of view only if the same instance of TransformedPositionis used for transforming many points between arbitrary CRS and this position CRS.
- 
       Note 2: This convenience class is useful when the source and target CRS are not likely to change often. If you are sure that the source and target CRS will not change at all for a given set of positions, then using CoordinateOperationdirectly gives better performances. This is becauseTransformedPositionchecks if the CRS changed before every transformations, which may be costly.
- 
       Note 3: This class is called Transformed Direct Position because it is more commonly used for transforming many points from arbitrary CRS to a common CRS (using the transform(Position)method) than the other way around.
 MyClassneeds 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.MyClasscould be written as below:public class MyClass { private static final CoordinateReferenceSystem PUBLIC_CRS = ... private static final CoordinateReferenceSystem INTERNAL_CRS = ... private final TransformedPosition myPosition = new TransformedPosition(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 GeneralPositionordinates
 
- 
 - 
Constructor SummaryConstructors Constructor Description TransformedPosition()Creates a new direct position initialized with the WGS84 CRS.TransformedPosition(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, Hints hints)Creates a new position which will contains the result of coordinate transformations fromsourceCRStotargetCRS.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description PositioninverseTransform()Returns a new point with the same coordinates than this one, but transformed in thesourceCRSgiven at construction time.PositioninverseTransform(CoordinateReferenceSystem crs)Returns a new point with the same coordinates than this one, but transformed in the given CRS.voidsetCoordinateReferenceSystem(CoordinateReferenceSystem crs)Sets the coordinate reference system in which the coordinate is given.voidtransform(Position position)Transforms a given position and stores the result in this object.- 
Methods inherited from class GeneralPositionclone, getCoordinate, getCoordinateReferenceSystem, getDimension, getOrdinate, hashCode, setLocation, setLocation, setLocation, setOrdinate, toPoint2D
 - 
Methods inherited from class AbstractPositioncheckCoordinateReferenceSystemDimension, equals, getDirectPosition, setPosition, toString
 
- 
 
- 
- 
- 
Constructor Detail- 
TransformedPositionpublic TransformedPosition() Creates a new direct position initialized with the WGS84 CRS.- Since:
- 2.3
 
 - 
TransformedPositionpublic TransformedPosition(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, Hints hints) throws FactoryRegistryException Creates a new position which will contains the result of coordinate transformations fromsourceCRStotargetCRS. The CRS associated with this position will be initially set totargetCRS.- Parameters:
- sourceCRS- The default CRS to be used by the- transform(position)- positionhas a null associated CRS. This- sourceCRSargument 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- setCoordinateReferenceSystemor- setLocation. This argument can not be null.
- hints- The set of hints to use for fetching a- CoordinateOperationFactory, or- nullif none.
- Throws:
- IllegalArgumentException- if- targetCRSwas- null.
- FactoryRegistryException- if no coordinate operation factory can be found for the specified hints.
- Since:
- 2.3
 
 
- 
 - 
Method Detail- 
setCoordinateReferenceSystempublic void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws MismatchedDimensionException Sets the coordinate reference system in which the coordinate is given. The given CRS will be used as:- the target CRS for every call to transform(Position)
- the source CRS for every call to
       inverseTransform(CoordinateReferenceSystem)
 - Overrides:
- setCoordinateReferenceSystemin class- GeneralPosition
- Parameters:
- crs- The new CRS for this direct position.
- Throws:
- MismatchedDimensionException- if the specified CRS doesn't have the expected number of dimensions.
 
- the target CRS for every call to 
 - 
transformpublic void transform(Position position) throws TransformException Transforms a given position and stores the result in this object.- 
       The source CRS is the CRS associated with the given position, or the sourceCRSargument given at construction time if and only if the CRS associated withpositionis null.
- 
       The target CRS is the CRS associated with this position. This is always the targetCRSargument given at construction time or by the last call tosetCoordinateReferenceSystem.
 - Parameters:
- position- A position using an arbitrary CRS. This object will not be modified.
- Throws:
- TransformException- if a coordinate transformation was required and failed.
 
- 
       
 - 
inverseTransformpublic Position 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 returnsthis, 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
 
 - 
inverseTransformpublic Position inverseTransform() throws TransformException Returns a new point with the same coordinates than this one, but transformed in thesourceCRSgiven at construction time. This method never returnsthis, 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
 
 
- 
 
-