| java.lang.Object org.geotools.geometry.AbstractDirectPosition org.geotools.geometry.GeneralDirectPosition org.geotools.geometry.TransformedDirectPosition
TransformedDirectPosition | public class TransformedDirectPosition extends GeneralDirectPosition (Code) | | A direct position capable to
a point between an arbitrary CRS
and
. This class caches the last transform
used in order to improve the performances when the
and
CRS don't change often. Using
this class is faster than invoking
(sourceCRS, targetCRS) for every points.
Note 1:
This class is advantageous on a performance point of view only if the same instance of
TransformedDirectPosition is used for transforming many points between arbitrary
CRS and this
.
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
TransformedDirectPosition 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
TransformedDirectPosition.transform(DirectPosition) 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 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 version: $Id: TransformedDirectPosition.java 25050 2007-04-06 00:41:49Z jgarnett $ |
Constructor Summary | |
public | TransformedDirectPosition() Creates a new direct position initialized with the
CRS. | public | 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 | |
public DirectPosition | inverseTransform(CoordinateReferenceSystem crs) Returns a new point with the same coordinates than this one, but transformed in the given
CRS. | public DirectPosition | inverseTransform() Returns a new point with the same coordinates than this one, but transformed in the
sourceCRS given at
. | public void | setCoordinateReferenceSystem(CoordinateReferenceSystem crs) Sets the coordinate reference system in which the coordinate is given. | public void | transform(DirectPosition position) Transforms a given position and stores the result in this object.
|
TransformedDirectPosition | public TransformedDirectPosition()(Code) | | Creates a new direct position initialized with the
CRS.
since: 2.3 |
inverseTransform | public DirectPosition inverseTransform(CoordinateReferenceSystem crs) throws TransformException(Code) | | 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. 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(Code) | | Returns a new point with the same coordinates than this one, but transformed in the
sourceCRS given at
. This method never returns
this ,
so the returned point usually doesn't need to be cloned.
The same position than this , but transformed in the source CRS. throws: TransformException - if a coordinate transformation was required and failed. since: 2.3 |
setCoordinateReferenceSystem | public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws MismatchedDimensionException(Code) | | Sets the coordinate reference system in which the coordinate is given.
The given CRS will be used as:
Parameters: crs - The new CRS for this direct position. throws: MismatchedDimensionException - if the specified CRS doesn't have the expectednumber of dimensions. |
transform | public void transform(DirectPosition position) throws TransformException(Code) | | Transforms a given position and stores the result in this object.
The
is the
, or the
sourceCRS argument given at
if and only if
the CRS associated with
position is null.
The
is the
. This is always the
targetCRS argument given at
or by the last call to
TransformedDirectPosition.setCoordinateReferenceSystemsetCoordinateReferenceSystem .
Parameters: position - A position using an arbitrary CRS. This object will not be modified. throws: TransformException - if a coordinate transformation was required and failed. |
Fields inherited from org.geotools.geometry.GeneralDirectPosition | final public double[] ordinates(Code)(Java Doc)
|
|
|