|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectAbstractDirectPosition
GeneralDirectPosition
TransformedDirectPosition
public class TransformedDirectPosition
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
TransformedDirectPosition
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 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
transform(DirectPosition)
method) than the other way around.
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); } }
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, getCoordinates, getDirectPosition, getPosition, setPosition, toString |
Methods inherited from class Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TransformedDirectPosition()
public TransformedDirectPosition(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS, Hints hints) throws FactoryRegistryException
sourceCRS
to targetCRS
. The CRS
associated with this position will be initially set to targetCRS
.
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.
IllegalArgumentException
- if targetCRS
was null
.
FactoryRegistryException
- if no coordinate
operation factory can be found for the specified hints.Method Detail |
---|
public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) throws MismatchedDimensionException
transform(DirectPosition)
inverseTransform(CoordinateReferenceSystem)
setCoordinateReferenceSystem
in class GeneralDirectPosition
crs
- The new CRS for this direct position.
MismatchedDimensionException
- if the specified CRS doesn't have the expected
number of dimensions.public void transform(DirectPosition position) throws TransformException
The source CRS is the
CRS associated with the given
position, or the sourceCRS
argument given at
construction time if and only if
the CRS associated with position
is null.
The target CRS is the CRS associated with this position. This is always the
targetCRS
argument given at construction time or by the last call to setCoordinateReferenceSystem
.
position
- A position using an arbitrary CRS. This object will not be modified.
TransformException
- if a coordinate transformation was required and failed.public DirectPosition inverseTransform(CoordinateReferenceSystem crs) throws TransformException
this
, so the returned point usually doesn't need to
be cloned.
crs
- The CRS for the position to be returned.
this
, but transformed in the specified CRS.
TransformException
- if a coordinate transformation was required and failed.public DirectPosition inverseTransform() throws TransformException
sourceCRS
given at construction time. This method never returns this
,
so the returned point usually doesn't need to be cloned.
this
, but transformed in the source CRS.
TransformException
- if a coordinate transformation was required and failed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |