|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.geometry.GeneralDirectPosition org.geotools.geometry.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 is used for transforming many points between arbitrary CRS and the CRS of this position.
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 are
frozen for a given set of positions, then using CoordinateOperation
directly gives much
better performances. This is because checks if the CRS changed
before every transformations, which may be costly.
Note 3: This class is called Transformed Direct Position because
its more commonly used for transforming many points from arbitrary CRS to a common CRS (using
the 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 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. could be written as below:
public class MyClass { private static final CoordinateReferenceSystem INTERNAL_CRS = ... private static final CoordinateReferenceSystem PUBLIC_CRS = ... private final TransformedDirectPosition myPosition = new TransformedDirectPosition(INTERNAL_CRS, null); public DirectPosition getPosition() throws TransformException { return myPosition.transform(PUBLIC_CRS); } 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); } }
Field Summary |
Fields inherited from class org.geotools.geometry.GeneralDirectPosition |
ordinates |
Constructor Summary | |
TransformedDirectPosition()
Creates a new direct position with the WGS84 CRS. |
|
TransformedDirectPosition(org.opengis.referencing.crs.CoordinateReferenceSystem crs,
Hints hints)
Creates a new direct position with the specified coordinate reference system. |
Method Summary | |
void |
setCoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Sets the coordinate reference system in which the coordinate is given. |
org.opengis.spatialschema.geometry.DirectPosition |
transform(org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS)
Returns a new point with the same coordinates than this one, but transformed in the given CRS. |
void |
transform(org.opengis.spatialschema.geometry.DirectPosition position)
Transforms a given position and stores the result in this object. |
Methods inherited from class org.geotools.geometry.GeneralDirectPosition |
clone, getCoordinateReferenceSystem, getCoordinates, getDimension, getOrdinate, getPosition, hashCode, setLocation, setLocation, setLocation, setOrdinate, toPoint2D, toString |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public TransformedDirectPosition()
public TransformedDirectPosition(org.opengis.referencing.crs.CoordinateReferenceSystem crs, Hints hints)
crs
- The CRS for this direct position.hints
- The set of hints to use for fetching a CoordinateOperationFactory
,
or if none.Method Detail |
public void setCoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws org.opengis.spatialschema.geometry.MismatchedDimensionException
transform(CoordinateReferenceSystem)
transform(DirectPosition)
setCoordinateReferenceSystem
in class GeneralDirectPosition
crs
- The new CRS for this direct position.
org.opengis.spatialschema.geometry.MismatchedDimensionException
- if the specified CRS doesn't have the expected
number of dimensions.public org.opengis.spatialschema.geometry.DirectPosition transform(org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS) throws org.opengis.referencing.operation.TransformException
targetCRS
- the target CRS.
org.opengis.referencing.operation.TransformException
- if a coordinate transformation was required and failed.public void transform(org.opengis.spatialschema.geometry.DirectPosition position) throws org.opengis.referencing.operation.TransformException
position
- A position using an arbitrary CRS. This object will not be modified.
org.opengis.referencing.operation.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 |