001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2005, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.referencing.operation.transform;
018:
019: // JUnit dependencies
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: // OpenGIS dependencies
025: import org.opengis.parameter.ParameterValueGroup;
026: import org.opengis.referencing.FactoryException;
027: import org.opengis.referencing.datum.Ellipsoid;
028: import org.opengis.referencing.operation.TransformException;
029: import org.opengis.referencing.operation.MathTransform;
030: import org.opengis.referencing.operation.MathTransformFactory;
031:
032: // Geotools dependencies
033: import org.geotools.referencing.ReferencingFactoryFinder;
034: import org.geotools.referencing.operation.TestTransform;
035: import org.geotools.referencing.datum.DefaultEllipsoid;
036: import org.geotools.geometry.GeneralDirectPosition;
037:
038: /**
039: * Tests the {@link GeocentricTranslation} class.
040: *
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/operation/transform/GeocentricTranslationTest.java $
042: * @version $Id: GeocentricTranslationTest.java 25050 2007-04-06 00:41:49Z jgarnett $
043: * @author Martin Desruisseaux
044: */
045: public final class GeocentricTranslationTest extends TestCase {
046: /**
047: * Runs the tests with the textual test runner.
048: */
049: public static void main(String args[]) {
050: junit.textui.TestRunner.run(suite());
051: }
052:
053: /**
054: * Returns the test suite.
055: */
056: public static Test suite() {
057: return new TestSuite(GeocentricTranslationTest.class);
058: }
059:
060: /**
061: * Constructs a test case with the given name.
062: */
063: public GeocentricTranslationTest(final String name) {
064: super (name);
065: }
066:
067: /**
068: * Test case using example from EPSG Guidance Note number 7 part 2 (May 2005),
069: * section 2.4.3.1.
070: */
071: public void testTranslation() throws FactoryException,
072: TransformException {
073: final String classification = "Geocentric translations";
074: final MathTransformFactory factory = ReferencingFactoryFinder
075: .getMathTransformFactory(null);
076: final ParameterValueGroup param = factory
077: .getDefaultParameters(classification);
078:
079: param.parameter("dx").setValue(84.87);
080: param.parameter("dy").setValue(96.49);
081: param.parameter("dz").setValue(116.95);
082:
083: final MathTransform test = factory
084: .createParameterizedTransform(param);
085: final GeneralDirectPosition position = new GeneralDirectPosition(
086: 3);
087: position.setOrdinate(0, 3771793.97);
088: position.setOrdinate(1, 140253.34);
089: position.setOrdinate(2, 5124304.35);
090: assertSame(position, test.transform(position, position));
091: assertEquals(3771878.84, position.getOrdinate(0), 1E-5);
092: assertEquals(140349.83, position.getOrdinate(1), 1E-5);
093: assertEquals(5124421.30, position.getOrdinate(2), 1E-5);
094: }
095:
096: /**
097: * Test case using example from EPSG Guidance Note number 7 part 2 (May 2005),
098: * section 2.4.3.2.1.
099: */
100: public void testSevenParam() throws FactoryException,
101: TransformException {
102: final String classification = "Position Vector 7-param. transformation";
103: final MathTransformFactory factory = ReferencingFactoryFinder
104: .getMathTransformFactory(null);
105: final ParameterValueGroup param = factory
106: .getDefaultParameters(classification);
107:
108: param.parameter("dx").setValue(0.000);
109: param.parameter("dy").setValue(0.000);
110: param.parameter("dz").setValue(4.5);
111: param.parameter("ex").setValue(0.000);
112: param.parameter("ey").setValue(0.000);
113: param.parameter("ez").setValue(0.554);
114: param.parameter("ppm").setValue(0.219);
115:
116: final MathTransform test = factory
117: .createParameterizedTransform(param);
118: final GeneralDirectPosition position = new GeneralDirectPosition(
119: 3);
120: position.setOrdinate(0, 3657660.66);
121: position.setOrdinate(1, 255768.55);
122: position.setOrdinate(2, 5201382.11);
123: assertSame(position, test.transform(position, position));
124: assertEquals(3657660.78, position.getOrdinate(0), 1E-2);
125: assertEquals(255778.43, position.getOrdinate(1), 1E-5);
126: assertEquals(5201387.75, position.getOrdinate(2), 1E-2);
127: }
128:
129: /**
130: * Test case using example from EPSG Guidance Note number 7 part 2 (May 2005),
131: * section 2.4.3.2.2.
132: */
133: public void testFrameRotation() throws FactoryException,
134: TransformException {
135: final String classification = "Coordinate Frame rotation";
136: final MathTransformFactory factory = ReferencingFactoryFinder
137: .getMathTransformFactory(null);
138: final ParameterValueGroup param = factory
139: .getDefaultParameters(classification);
140:
141: param.parameter("dx").setValue(0.000);
142: param.parameter("dy").setValue(0.000);
143: param.parameter("dz").setValue(4.5);
144: param.parameter("ex").setValue(0.000);
145: param.parameter("ey").setValue(0.000);
146: param.parameter("ez").setValue(-0.554);
147: param.parameter("ppm").setValue(0.219);
148:
149: final MathTransform test = factory
150: .createParameterizedTransform(param);
151: final GeneralDirectPosition position = new GeneralDirectPosition(
152: 3);
153: position.setOrdinate(0, 3657660.66);
154: position.setOrdinate(1, 255768.55);
155: position.setOrdinate(2, 5201382.11);
156: assertSame(position, test.transform(position, position));
157: assertEquals(3657660.78, position.getOrdinate(0), 1E-2);
158: assertEquals(255778.43, position.getOrdinate(1), 1E-5);
159: assertEquals(5201387.75, position.getOrdinate(2), 1E-2);
160: }
161:
162: /**
163: * Tests the creation with geocentric transforms.
164: * Note: the expected values here are approximatives since we didn't used
165: * an external source of test points for this test.
166: */
167: public void testGeotoolsExtensions() throws FactoryException,
168: TransformException {
169: final String classification = "Coordinate Frame rotation";
170: final MathTransformFactory factory = ReferencingFactoryFinder
171: .getMathTransformFactory(null);
172: final ParameterValueGroup param = factory
173: .getDefaultParameters(classification);
174: final Ellipsoid sourceEllipsoid = DefaultEllipsoid.INTERNATIONAL_1924;
175: final Ellipsoid targetEllipsoid = DefaultEllipsoid.WGS84;
176:
177: param.parameter("dx").setValue(0.000);
178: param.parameter("dy").setValue(0.000);
179: param.parameter("dz").setValue(4.5);
180: param.parameter("ex").setValue(0.000);
181: param.parameter("ey").setValue(0.000);
182: param.parameter("ez").setValue(-0.554);
183: param.parameter("ppm").setValue(0.219);
184:
185: param.parameter("src_dim").setValue(3);
186: param.parameter("tgt_dim").setValue(3);
187: param.parameter("src_semi_major").setValue(
188: sourceEllipsoid.getSemiMajorAxis());
189: param.parameter("src_semi_minor").setValue(
190: sourceEllipsoid.getSemiMinorAxis());
191: param.parameter("tgt_semi_major").setValue(
192: targetEllipsoid.getSemiMajorAxis());
193: param.parameter("tgt_semi_minor").setValue(
194: targetEllipsoid.getSemiMinorAxis());
195:
196: final MathTransform test = factory
197: .createParameterizedTransform(param);
198: final GeneralDirectPosition position = new GeneralDirectPosition(
199: 3);
200: position.setOrdinate(0, 4.00); // Longitude
201: position.setOrdinate(1, 55.00); // Latitude
202: position.setOrdinate(2, -191.61); // Height
203:
204: assertSame(position, test.transform(position, position));
205: assertEquals(4.00, position.getOrdinate(0), 1E-2);
206: assertEquals(55.00, position.getOrdinate(1), 1E-2);
207: assertEquals(3.23, position.getOrdinate(2), 1E-2);
208: }
209: }
|