org.geotools.referencing.operation.transform
Class AbstractMathTransform

java.lang.Object
  extended byorg.geotools.referencing.wkt.Formattable
      extended byorg.geotools.referencing.operation.transform.AbstractMathTransform
All Implemented Interfaces:
org.opengis.referencing.operation.MathTransform
Direct Known Subclasses:
AbstractMathTransform.Inverse, ConcatenatedTransform, ExponentialTransform1D, GeocentricTransform, IdentityTransform, LinearTransform1D, LogarithmicTransform1D, MapProjection, MolodenskiTransform, NADCONTransform, PassThroughTransform, ProjectiveTransform, WarpTransform2D

public abstract class AbstractMathTransform
extends Formattable
implements org.opengis.referencing.operation.MathTransform

Provides a default implementation for most methods required by the MathTransform interface. provides a convenient base class from which other transform classes can be easily derived. In addition, implements methods required by the MathTransform2D interface, but does not implements . Subclasses must declare implements MathTransform2D themself if they know to maps two-dimensional coordinate systems.

Since:
2.0
Version:
$Id: AbstractMathTransform.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Nested Class Summary
protected  class AbstractMathTransform.Inverse
          Default implementation for inverse math transform.
 
Constructor Summary
protected AbstractMathTransform()
          Constructs a math transform.
 
Method Summary
 java.awt.Shape createTransformedShape(java.awt.Shape shape)
          Transform the specified shape.
 org.opengis.referencing.operation.Matrix derivative(org.opengis.spatialschema.geometry.DirectPosition point)
          Gets the derivative of this transform at a point.
 org.opengis.referencing.operation.Matrix derivative(java.awt.geom.Point2D point)
          Gets the derivative of this transform at a point.
protected static void ensureNonNull(java.lang.String name, java.lang.Object object)
          Makes sure that an argument is non-null.
 boolean equals(java.lang.Object object)
          Compares the specified object with this math transform for equality.
protected  java.lang.String formatWKT(Formatter formatter)
          Format the inner part of a Well Known Text (WKT) element.
 int getDimSource()
          Deprecated. Renamed getSourceDimensions() for consistency with OperationMethod.
 int getDimTarget()
          Deprecated. Renamed getTargetDimensions() for consistency with OperationMethod.
 org.opengis.parameter.ParameterDescriptorGroup getParameterDescriptors()
          Returns the parameter descriptors for this math transform, or if unknow.
 org.opengis.parameter.ParameterValueGroup getParameterValues()
          Returns the parameter values for this math transform, or 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.
 org.opengis.referencing.operation.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 rollLongitude(double x)
          Ensures that the specified longitude stay within ±π radians.
 org.opengis.spatialschema.geometry.DirectPosition transform(org.opengis.spatialschema.geometry.DirectPosition ptSrc, org.opengis.spatialschema.geometry.DirectPosition ptDst)
          Transforms the specified and stores the result in .
 void transform(float[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts)
          Transforms a list of coordinate point ordinal values.
 java.awt.geom.Point2D transform(java.awt.geom.Point2D ptSrc, java.awt.geom.Point2D ptDst)
          Transforms the specified and stores the result in .
 
Methods inherited from class org.geotools.referencing.wkt.Formattable
toString, toWKT, toWKT, toWKT
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opengis.referencing.operation.MathTransform
toWKT, transform
 

Constructor Detail

AbstractMathTransform

protected AbstractMathTransform()
Constructs a math transform.

Method Detail

getDimSource

public final int getDimSource()
Deprecated. Renamed getSourceDimensions() for consistency with OperationMethod.

Gets the dimension of input points.


getSourceDimensions

public abstract int getSourceDimensions()
Gets the dimension of input points.

Specified by:
getSourceDimensions in interface org.opengis.referencing.operation.MathTransform

getDimTarget

public final int getDimTarget()
Deprecated. Renamed getTargetDimensions() for consistency with OperationMethod.

Gets the dimension of output points.


getTargetDimensions

public abstract int getTargetDimensions()
Gets the dimension of output points.

Specified by:
getTargetDimensions in interface org.opengis.referencing.operation.MathTransform

getParameterDescriptors

public org.opengis.parameter.ParameterDescriptorGroup getParameterDescriptors()
Returns the parameter descriptors for this math transform, or if unknow. This method is similar to OperationMethod.getParameters(), except that returns parameters in standard units (usually meters or degrees).

Returns:
The parameter descriptors for this math transform, or .
See Also:
OperationMethod.getParameters()

getParameterValues

public org.opengis.parameter.ParameterValueGroup getParameterValues()
Returns the parameter values for this math transform, or if unknow. This method is similar to Operation.getParameterValues(), except that returns parameters in standard units (usually meters or 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 .
See Also:
Operation.getParameterValues()

isIdentity

public boolean isIdentity()
Tests whether this transform does not move any points. The default implementation always returns .

Specified by:
isIdentity in interface org.opengis.referencing.operation.MathTransform

transform

public java.awt.geom.Point2D transform(java.awt.geom.Point2D ptSrc,
                                       java.awt.geom.Point2D ptDst)
                                throws org.opengis.referencing.operation.TransformException
Transforms the specified and stores the result in . The default implementation invokes MathTransform.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 transforming , or .
Returns:
the coordinate point after transforming and storing the result in .
Throws:
org.opengis.spatialschema.geometry.MismatchedDimensionException - if this transform doesn't map two-dimensional coordinate systems.
org.opengis.referencing.operation.TransformException - if the point can't be transformed.
See Also:
MathTransform2D.transform(Point2D,Point2D)

transform

public org.opengis.spatialschema.geometry.DirectPosition transform(org.opengis.spatialschema.geometry.DirectPosition ptSrc,
                                                                   org.opengis.spatialschema.geometry.DirectPosition ptDst)
                                                            throws org.opengis.referencing.operation.TransformException
Transforms the specified and stores the result in . The default implementation invokes MathTransform.transform(double[],int,double[],int,int).

Specified by:
transform in interface org.opengis.referencing.operation.MathTransform
Throws:
org.opengis.referencing.operation.TransformException

transform

public void transform(float[] srcPts,
                      int srcOff,
                      float[] dstPts,
                      int dstOff,
                      int numPts)
               throws org.opengis.referencing.operation.TransformException
Transforms a list of coordinate point ordinal values. The default implementation invokes MathTransform.transform(double[],int,double[],int,int) using a temporary array of doubles.

Specified by:
transform in interface org.opengis.referencing.operation.MathTransform
Throws:
org.opengis.referencing.operation.TransformException

createTransformedShape

public java.awt.Shape createTransformedShape(java.awt.Shape shape)
                                      throws org.opengis.referencing.operation.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 if this transform is the identity transform.
Throws:
java.lang.IllegalStateException - if this transform doesn't map 2D coordinate systems.
org.opengis.referencing.operation.TransformException - if a transform failed.
See Also:
MathTransform2D.createTransformedShape(Shape)

derivative

public org.opengis.referencing.operation.Matrix derivative(java.awt.geom.Point2D point)
                                                    throws org.opengis.referencing.operation.TransformException
Gets the derivative of this transform at a point. The default implementation always throw an exception. Subclasses that implement the MathTransform2D interface should override this method. Other subclasses should override derivative(DirectPosition) instead.

Parameters:
point - The coordinate point where to evaluate the derivative.
Returns:
The derivative at the specified point as a 2×2 matrix.
Throws:
org.opengis.spatialschema.geometry.MismatchedDimensionException - if the input dimension is not 2.
org.opengis.referencing.operation.TransformException - if the derivative can't be evaluated at the specified point.
See Also:
MathTransform2D.derivative(Point2D)

derivative

public org.opengis.referencing.operation.Matrix derivative(org.opengis.spatialschema.geometry.DirectPosition point)
                                                    throws org.opengis.referencing.operation.TransformException
Gets the derivative of this transform at a point. The default implementation ensure that has a valid dimension. Next, it try to delegate the work to an other method: Otherwise, a TransformException is thrown.

Specified by:
derivative in interface org.opengis.referencing.operation.MathTransform
Parameters:
point - The coordinate point where to evaluate the derivative.
Returns:
The derivative at the specified point (never ).
Throws:
java.lang.NullPointerException - if the derivative dependents on coordinate and is .
org.opengis.spatialschema.geometry.MismatchedDimensionException - if doesn't have the expected dimension.
org.opengis.referencing.operation.TransformException - if the derivative can't be evaluated at the specified point.

inverse

public org.opengis.referencing.operation.MathTransform inverse()
                                                        throws org.opengis.referencing.operation.NoninvertibleTransformException
Creates the inverse transform of this object. The default implementation returns if this transform is an identity transform, and throws a NoninvertibleTransformException otherwise. Subclasses should override this method.

Specified by:
inverse in interface org.opengis.referencing.operation.MathTransform
Throws:
org.opengis.referencing.operation.NoninvertibleTransformException

hashCode

public int hashCode()
Returns a hash value for this transform.


equals

public boolean equals(java.lang.Object object)
Compares the specified object with this math transform for equality. The default implementation checks if is an instance of the same class than and use the same parameter descriptor. Subclasses should override this method in order to compare internal fields.


formatWKT

protected java.lang.String formatWKT(Formatter formatter)
Format the inner part of a Well Known Text (WKT) element. The default implementation formats all parameter values returned by getParameterValues(). The parameter group name is used as the math transform name.

Overrides:
formatWKT in class Formattable
Parameters:
formatter - The formatter to use.
Returns:
The WKT element name, which is in the default implementation.
See Also:
Formattable.toWKT(), Formattable.toString()

ensureNonNull

protected static void ensureNonNull(java.lang.String name,
                                    java.lang.Object object)
                             throws java.lang.IllegalArgumentException
Makes sure that an argument is non-null. This is a convenience method for subclass constructors.

Parameters:
name - Argument name.
object - User argument.
Throws:
org.opengis.parameter.InvalidParameterValueException - if is null.
java.lang.IllegalArgumentException

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 for method implementation. This method make the following assumptions:



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


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.


Copyright © GeoTools. All Rights Reserved.