Class 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 invoking CoordinateOperationFactory.createOperation(sourceCRS, targetCRS) for every points.
    • Note 1: This class is advantageous on a performance point of view only if the same instance of TransformedPosition is 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 CoordinateOperation directly gives better performances. This is because TransformedPosition checks 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.

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