001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: *
005: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
006: * (C) 2005, Institut de Recherche pour le Développement
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * This package contains documentation from OpenGIS specifications.
019: * OpenGIS consortium's work is fully acknowledged here.
020: */
021: package org.geotools.referencing.operation.transform;
022:
023: // J2SE dependencies
024: import java.io.Serializable;
025:
026: // OpenGIS dependencies
027: import org.opengis.referencing.operation.MathTransform;
028: import org.opengis.referencing.operation.Matrix;
029: import org.opengis.referencing.operation.NoninvertibleTransformException;
030: import org.opengis.referencing.operation.TransformException;
031: import org.opengis.geometry.DirectPosition;
032: import org.opengis.geometry.MismatchedDimensionException;
033:
034: // Geotools dependencies
035: import org.geotools.resources.Utilities;
036:
037: /**
038: * A math transform which delegates part of its work to an other math transform. This is used
039: * as a starting point for subclass wanting to modifies only some aspect of an existing math
040: * transform, or to attach additional informations to it. The default implementation delegates
041: * all method calls to the {@linkplain #transform underlying transform}. Subclasses typically
042: * override some of those methods.
043: * <p>
044: * This class is serializable if the {@linkplain #transform underlying transform} is serializable
045: * too.
046: *
047: * @since 2.2
048: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/transform/MathTransformProxy.java $
049: * @version $Id: MathTransformProxy.java 24925 2007-03-27 20:12:08Z jgarnett $
050: * @author Martin Desruisseaux
051: */
052: public class MathTransformProxy implements MathTransform, Serializable {
053: /**
054: * Serial number for interoperability with different versions.
055: */
056: private static final long serialVersionUID = 8844242705205498128L;
057:
058: /**
059: * The math transform on which to delegate the work.
060: */
061: public final MathTransform transform;
062:
063: /**
064: * Creates a new proxy which delegates its work to the specified math transform.
065: */
066: protected MathTransformProxy(final MathTransform transform) {
067: this .transform = transform;
068: }
069:
070: /**
071: * Gets the dimension of input points.
072: */
073: public int getSourceDimensions() {
074: return transform.getTargetDimensions();
075: }
076:
077: /**
078: * Gets the dimension of output points.
079: */
080: public int getTargetDimensions() {
081: return transform.getSourceDimensions();
082: }
083:
084: /**
085: * Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}.
086: */
087: public DirectPosition transform(final DirectPosition ptSrc,
088: final DirectPosition ptDst)
089: throws MismatchedDimensionException, TransformException {
090: return transform.transform(ptSrc, ptDst);
091: }
092:
093: /**
094: * Transforms a list of coordinate point ordinal values.
095: */
096: public void transform(final double[] srcPts, final int srcOff,
097: final double[] dstPts, final int dstOff, final int numPts)
098: throws TransformException {
099: transform.transform(srcPts, srcOff, dstPts, dstOff, numPts);
100: }
101:
102: /**
103: * Transforms a list of coordinate point ordinal values.
104: */
105: public void transform(final float[] srcPts, final int srcOff,
106: final float[] dstPts, final int dstOff, final int numPts)
107: throws TransformException {
108: transform.transform(srcPts, srcOff, dstPts, dstOff, numPts);
109: }
110:
111: /**
112: * Gets the derivative of this transform at a point.
113: */
114: public Matrix derivative(final DirectPosition point)
115: throws TransformException {
116: return transform.derivative(point);
117: }
118:
119: /**
120: * Returns the inverse of this math transform.
121: */
122: public MathTransform inverse()
123: throws NoninvertibleTransformException {
124: return transform.inverse();
125: }
126:
127: /**
128: * Tests whether this transform does not move any points.
129: */
130: public boolean isIdentity() {
131: return transform.isIdentity();
132: }
133:
134: /**
135: * Returns a <cite>Well Known Text</cite> (WKT) for this transform.
136: */
137: public String toWKT() throws UnsupportedOperationException {
138: return transform.toWKT();
139: }
140:
141: /**
142: * Returns a string representation for this transform.
143: */
144: public String toString() {
145: return transform.toString();
146: }
147:
148: /**
149: * Compares the specified object with this inverse math transform for equality.
150: */
151: public boolean equals(final Object object) {
152: if (object != null && object.getClass().equals(getClass())) {
153: final MathTransformProxy that = (MathTransformProxy) object;
154: return Utilities.equals(this .transform, that.transform);
155: }
156: return false;
157: }
158:
159: /**
160: * Returns a hash code value for this math transform.
161: */
162: public int hashCode() {
163: return transform.hashCode() ^ (int) serialVersionUID;
164: }
165: }
|