Class AbstractMathTransform
- Object
-
- Formattable
-
- AbstractMathTransform
-
- All Implemented Interfaces:
MathTransform
- Direct Known Subclasses:
AbstractMathTransform.Inverse
,ConcatenatedTransform
,ExponentialTransform1D
,GeocentricTransform
,IdentityTransform
,LinearTransform1D
,LogarithmicTransform1D
,MapProjection
,MolodenskiTransform
,NADCONTransform
,NTv2Transform
,PassThroughTransform
,ProjectiveTransform
,VerticalTransform
,WarpTransform2D
public abstract class AbstractMathTransform extends Formattable implements MathTransform
Provides a default implementation for most methods required by theMathTransform
interface.AbstractMathTransform
provides a convenient base class from which other transform classes can be easily derived. In addition,AbstractMathTransform
implements methods required by theMathTransform2D
interface, but does not implementsMathTransform2D
. Subclasses must declareimplements MathTransform2D
themselves if they know to map two-dimensional coordinate systems.- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractMathTransform.Inverse
Default implementation for inverse math transform.
-
Field Summary
-
Fields inherited from class Formattable
SINGLE_LINE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMathTransform()
Constructs a math transform.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Shape
createTransformedShape(Shape shape)
Transform the specified shape.Matrix
derivative(Point2D point)
Gets the derivative of this transform at a point.Matrix
derivative(Position point)
Gets the derivative of this transform at a point.protected static void
ensureNonNull(String name, Object object)
Makes sure that an argument is non-null.boolean
equals(Object object)
Compares the specified object with this math transform for equality.protected String
formatWKT(Formatter formatter)
Format the inner part of a Well Known Text (WKT) element.String
getName()
Returns a name for this math transform (nevernull
).ParameterDescriptorGroup
getParameterDescriptors()
Returns the parameter descriptors for this math transform, ornull
if unknow.ParameterValueGroup
getParameterValues()
Returns the parameter values for this math transform, ornull
if unknow.abstract int
getSourceDimensions()
Gets the dimension of input points.abstract int
getTargetDimensions()
Gets the dimension of output points.int
hashCode()
Returns a hash value for this transform.MathTransform
inverse()
Creates the inverse transform of this object.boolean
isIdentity()
Tests whether this transform does not move any points.protected static boolean
needCopy(int srcOff, int dimSource, int dstOff, int dimTarget, int numPts)
Checks if source coordinates need to be copied before to apply the transformation.protected static double
normalizeAngle(double x)
Ensures that the specified longitude stay within 0 and {code}PI{code}.protected static double
rollLongitude(double x)
Ensures that the specified longitude stay within ±π radians.void
transform(double[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts)
Transforms a list of coordinate point ordinal values.void
transform(float[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts)
Transforms a list of coordinate point ordinal values.void
transform(float[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts)
Transforms a list of coordinate point ordinal values.Point2D
transform(Point2D ptSrc, Point2D ptDst)
Transforms the specifiedptSrc
and stores the result inptDst
.Position
transform(Position ptSrc, Position ptDst)
Transforms the specifiedptSrc
and stores the result inptDst
.-
Methods inherited from class Formattable
cleanupThreadLocals, toString, toWKT, toWKT, toWKT, toWKT
-
Methods inherited from interface MathTransform
toWKT, transform
-
-
-
-
Method Detail
-
getName
public String getName()
Returns a name for this math transform (nevernull
). This convenience methods returns the name of the parameter descriptors if any, or the short class name otherwise.- Returns:
- A name for this math transform (never
null
). - Since:
- 2.5
-
getSourceDimensions
public abstract int getSourceDimensions()
Gets the dimension of input points.- Specified by:
getSourceDimensions
in interfaceMathTransform
- Returns:
- The dimension of input points.
-
getTargetDimensions
public abstract int getTargetDimensions()
Gets the dimension of output points.- Specified by:
getTargetDimensions
in interfaceMathTransform
- Returns:
- The dimension of output points.
-
getParameterDescriptors
public ParameterDescriptorGroup getParameterDescriptors()
Returns the parameter descriptors for this math transform, ornull
if unknow. This method is similar toOperationMethod.getParameters()
, except thatMathTransform
returns parameters in standard units (usually meters or decimal degrees).- Returns:
- The parameter descriptors for this math transform, or
null
. - See Also:
OperationMethod.getParameters()
-
getParameterValues
public ParameterValueGroup getParameterValues()
Returns the parameter values for this math transform, ornull
if unknow. This method is similar toOperation.getParameterValues()
, except thatMathTransform
returns parameters in standard units (usually meters or decimal degrees). Since this method returns a copy of the parameter values, any change to a value will have no effect on this math transform.- Returns:
- A copy of the parameter values for this math transform, or
null
. - See Also:
Operation.getParameterValues()
-
isIdentity
public boolean isIdentity()
Tests whether this transform does not move any points. The default implementation always returnsfalse
.- Specified by:
isIdentity
in interfaceMathTransform
- Returns:
true
if thisMathTransform
is an identity transform;false
otherwise.
-
transform
public Point2D transform(Point2D ptSrc, Point2D ptDst) throws TransformException
Transforms the specifiedptSrc
and stores the result inptDst
. The default implementation invokesMathTransform.transform(double[],int,double[],int,int)
using a temporary array of doubles.- Parameters:
ptSrc
- The specified coordinate point to be transformed.ptDst
- The specified coordinate point that stores the result of transformingptSrc
, ornull
.- Returns:
- The coordinate point after transforming
ptSrc
and storing the result inptDst
. - Throws:
MismatchedDimensionException
- If this transform doesn't map two-dimensional coordinate systems.TransformException
- If the point can't be transformed.- See Also:
MathTransform2D.transform(Point2D,Point2D)
-
transform
public Position transform(Position ptSrc, Position ptDst) throws TransformException
Transforms the specifiedptSrc
and stores the result inptDst
. The default implementation delegates toMathTransform.transform(double[],int,double[],int,int)
.- Specified by:
transform
in interfaceMathTransform
- Parameters:
ptSrc
- the specified coordinate point to be transformed.ptDst
- the specified coordinate point that stores the result of transformingptSrc
, ornull
.- Returns:
- the coordinate point after transforming
ptSrc
and storing the result inptDst
, or a newly created point ifptDst
was null. - Throws:
TransformException
- if the point can't be transformed.
-
transform
public void transform(float[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) throws TransformException
Transforms a list of coordinate point ordinal values. The default implementation invokesMathTransform.transform(double[],int,double[],int,int)
using a temporary array of doubles.- Specified by:
transform
in interfaceMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned. May be the same thansrcPts
.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.- Throws:
TransformException
- if a point can't be transformed. Some implementations will stop at the first failure, wile some other implementations will fill the untransformable points with NaN values, continue and throw the exception only at end. Implementations that fall in the later case should set the last completed transform tothis
.
-
transform
public void transform(double[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) throws TransformException
Transforms a list of coordinate point ordinal values. The default implementation invokesMathTransform.transform(double[],int,double[],int,int)
using a temporary array of doubles.- Specified by:
transform
in interfaceMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.- Throws:
TransformException
- if a point can't be transformed. Some implementations will stop at the first failure, wile some other implementations will fill the untransformable points with NaN values, continue and throw the exception only at end. Implementations that fall in the later case should set the last completed transform tothis
.- Since:
- 2.5
-
transform
public void transform(float[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformException
Transforms a list of coordinate point ordinal values. The default implementation delegates toMathTransform.transform(double[],int,double[],int,int)
.- Specified by:
transform
in interfaceMathTransform
- Parameters:
srcPts
- the array containing the source point coordinates.srcOff
- the offset to the first point to be transformed in the source array.dstPts
- the array into which the transformed point coordinates are returned.dstOff
- the offset to the location of the first transformed point that is stored in the destination array.numPts
- the number of point objects to be transformed.- Throws:
TransformException
- if a point can't be transformed. Some implementations will stop at the first failure, wile some other implementations will fill the untransformable points with NaN values, continue and throw the exception only at end. Implementations that fall in the later case should set the last completed transform tothis
.- Since:
- 2.5
-
createTransformedShape
public Shape createTransformedShape(Shape shape) throws TransformException
Transform the specified shape. The default implementation computes quadratic curves using three points for each shape segments.- Parameters:
shape
- Shape to transform.- Returns:
- Transformed shape, or
shape
if this transform is the identity transform. - Throws:
IllegalStateException
- if this transform doesn't map 2D coordinate systems.TransformException
- if a transform failed.- See Also:
MathTransform2D.createTransformedShape(Shape)
-
derivative
public Matrix derivative(Point2D point) throws TransformException
Gets the derivative of this transform at a point. The default implementation always throw an exception. Subclasses that implement theMathTransform2D
interface should override this method. Other subclasses should overridederivative(Position)
instead.- Parameters:
point
- The coordinate point where to evaluate the derivative.- Returns:
- The derivative at the specified point as a 2×2 matrix.
- Throws:
MismatchedDimensionException
- if the input dimension is not 2.TransformException
- if the derivative can't be evaluated at the specified point.- See Also:
MathTransform2D.derivative(Point2D)
-
derivative
public Matrix derivative(Position point) throws TransformException
Gets the derivative of this transform at a point. The default implementation ensure thatpoint
has a valid dimension. Next, it try to delegate the work to an other method:- If the input dimension is 2, then this method delegates the work to
derivative(Point2D)
. - If this object is an instance of
MathTransform1D
, then this method delegates the work toderivative(double)
.
TransformException
is thrown.- Specified by:
derivative
in interfaceMathTransform
- Parameters:
point
- The coordinate point where to evaluate the derivative.- Returns:
- The derivative at the specified point (never
null
). - Throws:
NullPointerException
- if the derivative dependents on coordinate andpoint
isnull
.MismatchedDimensionException
- ifpoint
doesn't have the expected dimension.TransformException
- if the derivative can't be evaluated at the specified point.
- If the input dimension is 2, then this method delegates the work to
-
inverse
public MathTransform inverse() throws NoninvertibleTransformException
Creates the inverse transform of this object. The default implementation returnsthis
if this transform is an identity transform, and throws aNoninvertibleTransformException
otherwise. Subclasses should override this method.- Specified by:
inverse
in interfaceMathTransform
- Returns:
- The inverse transform.
- Throws:
NoninvertibleTransformException
- if the transform can't be inversed.
-
hashCode
public int hashCode()
Returns a hash value for this transform.
-
equals
public boolean equals(Object object)
Compares the specified object with this math transform for equality. The default implementation checks ifobject
is an instance of the same class thanthis
and use the same parameter descriptor. Subclasses should override this method in order to compare internal fields.- Overrides:
equals
in classObject
- Parameters:
object
- The object to compare with this transform.- Returns:
true
if the given object is a transform of the same class and if, given identical source position, the transformed position would be the equals.
-
formatWKT
protected String formatWKT(Formatter formatter)
Format the inner part of a Well Known Text (WKT) element. The default implementation formats all parameter values returned bygetParameterValues()
. The parameter group name is used as the math transform name.- Overrides:
formatWKT
in classFormattable
- Parameters:
formatter
- The formatter to use.- Returns:
- The WKT element name, which is
"PARAM_MT"
in the default implementation. - See Also:
Formattable.toWKT()
,Formattable.toString()
-
ensureNonNull
protected static void ensureNonNull(String name, Object object) throws InvalidParameterValueException
Makes sure that an argument is non-null. This is a convenience method for subclass constructors.- Parameters:
name
- Argument name.object
- User argument.- Throws:
InvalidParameterValueException
- ifobject
is null.
-
needCopy
protected static boolean needCopy(int srcOff, int dimSource, int dstOff, int dimTarget, int numPts)
Checks if source coordinates need to be copied before to apply the transformation. This convenience method is provided fortransform(...)
method implementation. This method make the following assumptions:- Coordinates will be iterated from lower index to upper index.
- Coordinates are read and writen in shrunk. For example (longitude,latitude,height) values for one coordinate are read together, and the transformed (x,y,z) values are written together only after.
However, this method does not assumes that source and target dimension are the same (in the special case where source and target dimension are always the same, a simplier and more efficient check is possible). The following example prepares a transformation from 2 dimensional points to three dimensional points:
public void transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) { if (srcPts==dstPts && needCopy(srcOff, 2, dstOff, 3, numPts) { final double[] old = srcPts; srcPts = new double[numPts*2]; System.arraycopy(old, srcOff, srcPts, 0, srcPts.length); srcOff = 0; } }
This method is for internal usage by the referencing module only. Do not use! It will be replaced by a different mechanism in a future GeoTools version.
- Parameters:
srcOff
- The offset in the source coordinate array.dimSource
- The dimension of input points.dstOff
- The offset in the destination coordinate array.dimTarget
- The dimension of output points.numPts
- The number of points to transform.- Returns:
true
if the source coordinates should be copied before to apply the transformation in order to avoid an overlap with the destination array.
-
rollLongitude
protected static double rollLongitude(double x)
Ensures that the specified longitude stay within ±π radians. This method is typically invoked after geographic coordinates are transformed. This method may add or substract some amount of 2π radians to x.- Parameters:
x
- The longitude in radians.- Returns:
- The longitude in the range ±π radians.
-
normalizeAngle
protected static double normalizeAngle(double x)
Ensures that the specified longitude stay within 0 and {code}PI{code}.- Parameters:
x
- An angle- Returns:
- The normalized angle
-
-