001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2002, 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;
018:
019: // JUnit dependencies
020: import junit.framework.Test;
021: import junit.framework.TestSuite;
022:
023: // OpenGIS dependencies
024: import org.opengis.metadata.quality.PositionalAccuracy;
025: import org.opengis.parameter.ParameterValueGroup;
026: import org.opengis.referencing.FactoryException;
027: import org.opengis.referencing.crs.CompoundCRS;
028: import org.opengis.referencing.crs.CoordinateReferenceSystem;
029: import org.opengis.referencing.crs.GeographicCRS;
030: import org.opengis.referencing.crs.ProjectedCRS;
031: import org.opengis.referencing.operation.CoordinateOperation;
032: import org.opengis.referencing.operation.CoordinateOperationFactory;
033: import org.opengis.referencing.operation.Conversion;
034: import org.opengis.referencing.operation.MathTransform;
035: import org.opengis.referencing.operation.Operation;
036: import org.opengis.referencing.operation.OperationNotFoundException;
037: import org.opengis.referencing.operation.PassThroughOperation;
038: import org.opengis.referencing.operation.Projection;
039: import org.opengis.referencing.operation.Transformation;
040:
041: // Geotools dependencies
042: import org.geotools.factory.Hints;
043: import org.geotools.referencing.ReferencingFactoryFinder;
044: import org.geotools.referencing.crs.DefaultGeographicCRS;
045: import org.geotools.referencing.crs.DefaultEngineeringCRS;
046: import org.geotools.metadata.iso.quality.PositionalAccuracyImpl;
047:
048: /**
049: * Test the default coordinate operation factory.
050: * <p>
051: * <strong>NOTE:</strong> Some tests are disabled in the particular case when the
052: * {@link CoordinateOperationFactory} is actually an {@link AuthorityBackedFactory}
053: * instance. This is because the later can replace source or target CRS by some CRS
054: * found in the EPSG authority factory, causing {@code assertSame} to fails. It may
055: * also returns a more accurate operation than the one expected from the WKT in the
056: * code below, causing transformation checks to fail as well. This situation occurs
057: * only if some EPSG authority factory like {@code plugin/epsg-hsql} is found in the
058: * classpath while the test are running. It should not occurs during Maven build, so
059: * all tests should be executed with Maven. It may occurs during an execution from
060: * the IDE however, in which case the tests are disabled in order to allows normal
061: * execution of other tests.
062: *
063: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/operation/CoordinateOperationFactoryTest.java $
064: * @version $Id: CoordinateOperationFactoryTest.java 25262 2007-04-23 21:11:16Z desruisseaux $
065: * @author Martin Desruisseaux
066: */
067: public final class CoordinateOperationFactoryTest extends TestTransform {
068: /**
069: * Constructs a test case with the given name.
070: */
071: public CoordinateOperationFactoryTest(final String name) {
072: super (name);
073: }
074:
075: /**
076: * Uses reflection to dynamically create a test suite containing all
077: * the <code>testXXX()</code> methods - from the JUnit FAQ.
078: */
079: public static Test suite() {
080: return new TestSuite(CoordinateOperationFactoryTest.class);
081: }
082:
083: /**
084: * Runs the tests with the textual test runner.
085: */
086: public static void main(String args[]) {
087: junit.textui.TestRunner.run(suite());
088: }
089:
090: /**
091: * Ensures that positional accuracy dependencies are properly loaded. This is not needed for
092: * normal execution, but JUnit behavior with class loaders is sometime surprising.
093: */
094: protected void setUp() throws Exception {
095: super .setUp();
096: assertNotNull(PositionalAccuracyImpl.DATUM_SHIFT_APPLIED);
097: assertNotNull(PositionalAccuracyImpl.DATUM_SHIFT_OMITTED);
098: }
099:
100: /**
101: * Quick self test, in part to give this test suite a test
102: * and also to test the internal method.
103: */
104: public void testAssertPointsEqual() {
105: String name = "self test";
106: double a[] = { 10, 10 };
107: double b[] = { 10.1, 10.1 };
108: double delta[] = { 0.2, 0.2 };
109: assertPointsEqual(name, a, b, delta);
110: }
111:
112: /**
113: * Make sure that <code>createOperation(sourceCRS, targetCRS)</code>
114: * returns an identity transform when <code>sourceCRS</code> and <code>targetCRS</code>
115: * are identical, and tests the generic CRS.
116: *
117: * @todo uses static imports when we will be allowed to compile with J2SE 1.5.
118: */
119: public void testGenericTransform() throws FactoryException {
120: assertTrue(opFactory.createOperation(
121: DefaultGeographicCRS.WGS84, DefaultGeographicCRS.WGS84)
122: .getMathTransform().isIdentity());
123: assertTrue(opFactory.createOperation(
124: DefaultEngineeringCRS.CARTESIAN_2D,
125: DefaultEngineeringCRS.CARTESIAN_2D).getMathTransform()
126: .isIdentity());
127: assertTrue(opFactory.createOperation(
128: DefaultEngineeringCRS.CARTESIAN_3D,
129: DefaultEngineeringCRS.CARTESIAN_3D).getMathTransform()
130: .isIdentity());
131: assertTrue(opFactory.createOperation(
132: DefaultEngineeringCRS.GENERIC_2D,
133: DefaultEngineeringCRS.GENERIC_2D).getMathTransform()
134: .isIdentity());
135: assertTrue(opFactory.createOperation(
136: DefaultEngineeringCRS.GENERIC_2D,
137: DefaultEngineeringCRS.CARTESIAN_2D).getMathTransform()
138: .isIdentity());
139: assertTrue(opFactory.createOperation(
140: DefaultEngineeringCRS.CARTESIAN_2D,
141: DefaultEngineeringCRS.GENERIC_2D).getMathTransform()
142: .isIdentity());
143: assertTrue(opFactory.createOperation(
144: DefaultGeographicCRS.WGS84,
145: DefaultEngineeringCRS.GENERIC_2D).getMathTransform()
146: .isIdentity());
147: assertTrue(opFactory.createOperation(
148: DefaultEngineeringCRS.GENERIC_2D,
149: DefaultGeographicCRS.WGS84).getMathTransform()
150: .isIdentity());
151: try {
152: opFactory.createOperation(
153: DefaultEngineeringCRS.CARTESIAN_2D,
154: DefaultGeographicCRS.WGS84);
155: fail();
156: } catch (OperationNotFoundException exception) {
157: // This is the expected exception.
158: }
159: try {
160: opFactory.createOperation(DefaultGeographicCRS.WGS84,
161: DefaultEngineeringCRS.CARTESIAN_2D);
162: fail();
163: } catch (OperationNotFoundException exception) {
164: // This is the expected exception.
165: }
166: }
167:
168: /**
169: * Tests a transformation with unit conversion.
170: */
171: public void testUnitConversion() throws Exception {
172: // NOTE: TOWGS84[0,0,0,0,0,0,0] is used here as a hack for
173: // avoiding datum shift. Shifts will be tested later.
174: final CoordinateReferenceSystem targetCRS = crsFactory
175: .createFromWKT("PROJCS[\"TransverseMercator\",\n"
176: + " GEOGCS[\"Sphere\",\n"
177: + " DATUM[\"Sphere\",\n"
178: + " SPHEROID[\"Sphere\", 6370997.0, 0.0],\n"
179: + " TOWGS84[0,0,0,0,0,0,0]],\n"
180: + " PRIMEM[\"Greenwich\", 0.0],\n"
181: + " UNIT[\"degree\", 0.017453292519943295],\n"
182: + " AXIS[\"Longitude\", EAST],\n"
183: + " AXIS[\"Latitude\", NORTH]],\n"
184: + " PROJECTION[\"Transverse_Mercator\",\n"
185: + " AUTHORITY[\"OGC\",\"Transverse_Mercator\"]],\n"
186: + " PARAMETER[\"central_meridian\", 170.0],\n"
187: + " PARAMETER[\"latitude_of_origin\", 50.0],\n"
188: + " PARAMETER[\"scale_factor\", 0.95],\n"
189: + " PARAMETER[\"false_easting\", 0.0],\n"
190: + " PARAMETER[\"false_northing\", 0.0],\n"
191: + " UNIT[\"feet\", 0.304800609601219],\n"
192: + " AXIS[\"x\", EAST],\n"
193: + " AXIS[\"y\", NORTH]]\n");
194:
195: final CoordinateReferenceSystem sourceCRS = crsFactory
196: .createFromWKT("GEOGCS[\"Sphere\",\n"
197: + " DATUM[\"Sphere\",\n"
198: + " SPHEROID[\"Sphere\", 6370997.0, 0.0],\n"
199: + " TOWGS84[0,0,0,0,0,0,0]],\n"
200: + " PRIMEM[\"Greenwich\", 0.0],\n"
201: + " UNIT[\"degree\", 0.017453292519943295],\n"
202: + " AXIS[\"Longitude\", EAST],\n"
203: + " AXIS[\"Latitude\", NORTH]]\n");
204:
205: final CoordinateOperation operation = opFactory
206: .createOperation(sourceCRS, targetCRS);
207: assertEquals(sourceCRS, operation.getSourceCRS());
208: assertEquals(targetCRS, operation.getTargetCRS());
209: assertTrue(operation instanceof Projection);
210:
211: final ParameterValueGroup param = ((Operation) operation)
212: .getParameterValues();
213: assertEquals("semi_major", 6370997.0, param.parameter(
214: "semi_major").doubleValue(), 1E-5);
215: assertEquals("semi_minor", 6370997.0, param.parameter(
216: "semi_minor").doubleValue(), 1E-5);
217: assertEquals("latitude_of_origin", 50.0, param.parameter(
218: "latitude_of_origin").doubleValue(), 1E-8);
219: assertEquals("central_meridian", 170.0, param.parameter(
220: "central_meridian").doubleValue(), 1E-8);
221: assertEquals("scale_factor", 0.95, param.parameter(
222: "scale_factor").doubleValue(), 1E-8);
223: assertEquals("false_easting", 0.0, param.parameter(
224: "false_easting").doubleValue(), 1E-8);
225: assertEquals("false_northing", 0.0, param.parameter(
226: "false_northing").doubleValue(), 1E-8);
227:
228: final MathTransform transform = operation.getMathTransform();
229: assertInterfaced(transform);
230: assertTransformEquals2_2(transform.inverse(), 0, 0, 170, 50);
231: assertTransformEquals2_2(transform, 170, 50, 0, 0);
232: }
233:
234: /**
235: * Tests a transformation that requires a datum shift with TOWGS84[0,0,0].
236: * In addition, this method tests datum aliases.
237: */
238: public void testEllipsoidShift() throws Exception {
239: final CoordinateReferenceSystem sourceCRS = crsFactory
240: .createFromWKT("GEOGCS[\"NAD83\",\n"
241: + " DATUM[\"North_American_Datum_1983\",\n"
242: + " SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101,\n"
243: + " AUTHORITY[\"EPSG\",\"7019\"]],\n"
244: + " TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],\n"
245: + " AUTHORITY[\"EPSG\",\"6269\"]],\n"
246: + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],\n"
247: + " UNIT[\"degree\", 0.017453292519943295],\n"
248: + " AXIS[\"Lon\", EAST],\n"
249: + " AXIS[\"Lat\", NORTH],\n"
250: + " AUTHORITY[\"EPSG\",\"4269\"]]");
251:
252: final CoordinateReferenceSystem targetCRS = crsFactory
253: .createFromWKT("GEOGCS[\"GCS_WGS_1984\",\n"
254: + " DATUM[\"D_WGS_1984\",\n"
255: + " SPHEROID[\"WGS_1984\", 6378137.0, 298.257223563]],\n"
256: + " PRIMEM[\"Greenwich\", 0.0],\n"
257: + " UNIT[\"degree\", 0.017453292519943295],\n"
258: + " AXIS[\"Lon\", EAST],\n"
259: + " AXIS[\"Lat\", NORTH]]");
260:
261: final CoordinateOperation operation = opFactory
262: .createOperation(sourceCRS, targetCRS);
263: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
264: assertSame(sourceCRS, operation.getSourceCRS());
265: assertSame(targetCRS, operation.getTargetCRS());
266: }
267: final MathTransform transform = operation.getMathTransform();
268: assertInterfaced(transform);
269: assertTransformEquals2_2(transform, -180, -88.21076182660325,
270: -180, -88.21076182655470);
271: assertTransformEquals2_2(transform, +180, 85.41283436546335,
272: -180, 85.41283436531322);
273: // assertTransformEquals2_2(transform, +180, 85.41283436546335, +180, 85.41283436548373);
274: // Note 1: Expected values above were computed with Geotools (not an external library).
275: // Note 2: The commented-out test it the one we get when using geocentric instead of
276: // Molodenski method.
277: }
278:
279: /**
280: * Tests a transformation that requires a datum shift.
281: */
282: public void testDatumShift() throws Exception {
283: final CoordinateReferenceSystem sourceCRS = crsFactory
284: .createFromWKT("GEOGCS[\"NTF (Paris)\",\n"
285: + " DATUM[\"Nouvelle_Triangulation_Francaise\",\n"
286: + " SPHEROID[\"Clarke 1880 (IGN)\", 6378249.2, 293.466021293627,\n"
287: + " AUTHORITY[\"EPSG\",\"7011\"]],\n"
288: + " TOWGS84[-168,-60,320,0,0,0,0],\n"
289: + " AUTHORITY[\"EPSG\",\"6275\"]],\n"
290: + " PRIMEM[\"Paris\", 2.5969213, AUTHORITY[\"EPSG\",\"8903\"]],\n"
291: + " UNIT[\"grad\", 0.015707963267949, AUTHORITY[\"EPSG\", \"9105\"]],\n"
292: + " AXIS[\"Lat\",NORTH],\n"
293: + " AXIS[\"Long\",EAST],\n"
294: + " AUTHORITY[\"EPSG\",\"4807\"]]");
295:
296: final CoordinateReferenceSystem targetCRS = crsFactory
297: .createFromWKT("GEOGCS[\"WGS84\",\n"
298: + " DATUM[\"WGS84\",\n"
299: + " SPHEROID[\"WGS84\", 6378137.0, 298.257223563]],\n"
300: + " PRIMEM[\"Greenwich\", 0.0],\n"
301: + " UNIT[\"degree\", 0.017453292519943295],\n"
302: + "" + " AXIS[\"Longitude\",EAST],"
303: + " AXIS[\"Latitude\",NORTH]]");
304:
305: final CoordinateOperation operation = opFactory
306: .createOperation(sourceCRS, targetCRS);
307: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
308: assertSame(sourceCRS, operation.getSourceCRS());
309: assertSame(targetCRS, operation.getTargetCRS());
310: assertTrue(operation.getPositionalAccuracy().contains(
311: PositionalAccuracyImpl.DATUM_SHIFT_APPLIED));
312: assertFalse(operation.getPositionalAccuracy().contains(
313: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
314: }
315: final MathTransform transform = operation.getMathTransform();
316: assertInterfaced(transform);
317: assertTransformEquals2_2(transform, 0, 0, 2.3367521703619816,
318: 0.0028940088671177986);
319: assertTransformEquals2_2(transform, 20, -10,
320: -6.663517606186469, 18.00134508026729);
321: // Note: Expected values above were computed with Geotools (not an external library).
322: // However, it was tested with both Molodenski and Geocentric transformations.
323:
324: /*
325: * Remove the TOWGS84 element and test again. An exception should be throws,
326: * since no Bursa-Wolf parameters were available.
327: */
328: final CoordinateReferenceSystem amputedCRS;
329: if (true) {
330: String wkt = sourceCRS.toWKT();
331: final int start = wkt.indexOf("TOWGS84");
332: assertTrue(start >= 0);
333: final int end = wkt.indexOf(']', start);
334: assertTrue(end >= 0);
335: final int comma = wkt.indexOf(',', end);
336: assertTrue(comma >= 0);
337: wkt = wkt.substring(0, start) + wkt.substring(comma + 1);
338: amputedCRS = crsFactory.createFromWKT(wkt);
339: } else {
340: amputedCRS = sourceCRS;
341: }
342: try {
343: assertNotNull(opFactory.createOperation(amputedCRS,
344: targetCRS));
345: fail("Operation without Bursa-Wolf parameters should not have been allowed.");
346: } catch (OperationNotFoundException excption) {
347: // This is the expected exception.
348: }
349: /*
350: * Try again with hints, asking for a lenient factory.
351: */
352: CoordinateOperationFactory lenientFactory;
353: Hints hints = new Hints(Hints.LENIENT_DATUM_SHIFT,
354: Boolean.FALSE);
355: lenientFactory = ReferencingFactoryFinder
356: .getCoordinateOperationFactory(hints);
357: assertSame(opFactory, lenientFactory);
358: hints.put(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE);
359: lenientFactory = ReferencingFactoryFinder
360: .getCoordinateOperationFactory(hints);
361: assertNotSame(opFactory, lenientFactory);
362: final CoordinateOperation lenient = lenientFactory
363: .createOperation(amputedCRS, targetCRS);
364: assertSame(amputedCRS, lenient.getSourceCRS());
365: assertSame(targetCRS, lenient.getTargetCRS());
366: assertFalse(lenient.getPositionalAccuracy().contains(
367: PositionalAccuracyImpl.DATUM_SHIFT_APPLIED));
368: assertTrue(lenient.getPositionalAccuracy().contains(
369: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
370:
371: final MathTransform lenientTr = lenient.getMathTransform();
372: assertInterfaced(lenientTr);
373: assertTransformEquals2_2(lenientTr, 0, 0, 2.33722917, 0.0);
374: assertTransformEquals2_2(lenientTr, 20, -10, -6.66277083,
375: 17.99814879585781);
376: // assertTransformEquals2_2(lenientTr, 20, -10, -6.66277083, 17.998143675921714);
377: // Note 1: Expected values above were computed with Geotools (not an external library).
378: // Note 2: The commented-out test is the one we get with "Abridged_Molodenski" method
379: // instead of "Molodenski".
380: }
381:
382: /**
383: * Tests a transformation that requires a datum shift with 7 parameters.
384: */
385: public void testDatumShift7Param() throws Exception {
386: final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
387: final CoordinateReferenceSystem targetCRS = crsFactory
388: .createFromWKT("PROJCS[\"IGN53 Mare / UTM zone 58S\",\n"
389: + " GEOGCS[\"IGN53 Mare\",\n"
390: + " DATUM[\"IGN53 Mare\",\n"
391: + " SPHEROID[\"International 1924\", 6378388.0, 297.0, AUTHORITY[\"EPSG\",\"7022\"]],\n"
392: + " TOWGS84[-408.809, 366.856, -412.987, 1.8842, -0.5308, 2.1655, -24.978523651158998],\n"
393: + " AUTHORITY[\"EPSG\",\"6641\"]],\n"
394: + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],\n"
395: + " UNIT[\"degree\", 0.017453292519943295],\n"
396: + " AXIS[\"Geodetic latitude\", NORTH, AUTHORITY[\"EPSG\",\"106\"]],\n"
397: + " AXIS[\"Geodetic longitude\", EAST, AUTHORITY[\"EPSG\",\"107\"]],\n"
398: + " AUTHORITY[\"EPSG\",\"4641\"]],\n"
399: + " PROJECTION[\"Transverse Mercator\", AUTHORITY[\"EPSG\",\"9807\"]],\n"
400: + " PARAMETER[\"central_meridian\", 165.0],\n"
401: + " PARAMETER[\"latitude_of_origin\", 0.0],\n"
402: + " PARAMETER[\"scale_factor\", 0.9996],\n"
403: + " PARAMETER[\"false_easting\", 500000.0],\n"
404: + " PARAMETER[\"false_northing\", 10000000.0],\n"
405: + " UNIT[\"m\", 1.0],\n"
406: + " AXIS[\"Easting\", EAST, AUTHORITY[\"EPSG\",\"1\"]],\n"
407: + " AXIS[\"Northing\", NORTH, AUTHORITY[\"EPSG\",\"2\"]],\n"
408: + " AUTHORITY[\"EPSG\",\"2995\"]]");
409:
410: CoordinateOperation operation = opFactory.createOperation(
411: sourceCRS, targetCRS);
412: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
413: assertSame(sourceCRS, operation.getSourceCRS());
414: assertSame(targetCRS, operation.getTargetCRS());
415: assertTrue(operation.getPositionalAccuracy().contains(
416: PositionalAccuracyImpl.DATUM_SHIFT_APPLIED));
417: assertFalse(operation.getPositionalAccuracy().contains(
418: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
419: }
420: MathTransform transform = operation.getMathTransform();
421: assertInterfaced(transform);
422: assertTransformEquals2_2(transform, 168.1075, -21.597283333333,
423: 822023.338884308, 7608648.67486555);
424: // Note: Expected values above were computed with Geotools (not an external library).
425:
426: /*
427: * Try again using lenient factory. The result should be identical, since we do have
428: * Bursa-Wolf parameters. This test failed before GEOT-661 fix.
429: */
430: final Hints hints = new Hints(Hints.LENIENT_DATUM_SHIFT,
431: Boolean.TRUE);
432: final CoordinateOperationFactory lenientFactory = ReferencingFactoryFinder
433: .getCoordinateOperationFactory(hints);
434: assertNotSame(opFactory, lenientFactory);
435: operation = lenientFactory
436: .createOperation(sourceCRS, targetCRS);
437: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
438: assertSame(sourceCRS, operation.getSourceCRS());
439: assertSame(targetCRS, operation.getTargetCRS());
440: assertTrue(operation.getPositionalAccuracy().contains(
441: PositionalAccuracyImpl.DATUM_SHIFT_APPLIED));
442: assertFalse(operation.getPositionalAccuracy().contains(
443: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
444: }
445: transform = operation.getMathTransform();
446: assertInterfaced(transform);
447: assertTransformEquals2_2(transform, 168.1075, -21.597283333333,
448: 822023.338884308, 7608648.67486555);
449: // Note: Expected values above were computed with Geotools (not an external library).
450: }
451:
452: /**
453: * Tests transformations involving compound CRS.
454: */
455: public void testCompoundCRS() throws Exception {
456: final String WGS84 = "GEOGCS[\"WGS 84\",\n"
457: + " DATUM[\"WGS_1984\",\n"
458: + " SPHEROID[\"WGS 84\", 6378137, 298.257223563,\n"
459: + " AUTHORITY[\"EPSG\",\"7030\"]],\n"
460: + " TOWGS84[0,0,0,0,0,0,0],\n"
461: + " AUTHORITY[\"EPSG\",\"6326\"]],\n"
462: + " PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\",\"8901\"]],\n"
463: + " UNIT[\"DMSH\",0.0174532925199433, AUTHORITY[\"EPSG\",\"9108\"]],\n"
464: + " AXIS[\"Lat\",NORTH],\n"
465: + " AXIS[\"Long\",EAST],\n"
466: + " AUTHORITY[\"EPSG\",\"4326\"]]\n";
467:
468: final String NAD27 = "GEOGCS[\"NAD27\",\n"
469: + " DATUM[\"North_American_Datum_1927\",\n"
470: + " SPHEROID[\"Clarke 1866\", 6378206.4, 294.978698213901,\n"
471: + " AUTHORITY[\"EPSG\",\"7008\"]],\n"
472: + " TOWGS84[-3,142,183,0,0,0,0],\n"
473: + " AUTHORITY[\"EPSG\",\"6267\"]],\n"
474: + " PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\",\"8901\"]],\n"
475: + " UNIT[\"DMSH\",0.0174532925199433, AUTHORITY[\"EPSG\",\"9108\"]],\n"
476: + " AXIS[\"Lat\",NORTH],\n"
477: + " AXIS[\"Long\",EAST],\n"
478: + " AUTHORITY[\"EPSG\",\"4267\"]]\n";
479:
480: final String Z = "VERT_CS[\"ellipsoid Z in meters\",\n" + ""
481: + " VERT_DATUM[\"Ellipsoid\",2002],\n"
482: + " UNIT[\"metre\", 1],\n" + " AXIS[\"Z\",UP]]";
483:
484: final String H = "VERT_CS[\"mean sea level height\",\n"
485: + " VERT_DATUM[\"Mean Sea Level\", 2005, AUTHORITY[\"EPSG\",\"5100\"]],\n"
486: + " UNIT[\"metre\", 1, AUTHORITY[\"EPSG\",\"9001\"]],\n"
487: + " AXIS[\"Z\",UP], AUTHORITY[\"EPSG\",\"5714\"]]\n";
488:
489: final String WGS84_Z = "COMPD_CS[\"Wgs84 with height Z\","
490: + WGS84 + "," + Z + "]";
491: final String NAD27_Z = "COMPD_CS[\"NAD27 with height Z\","
492: + NAD27 + "," + Z + "]";
493: final String Z_NAD27 = "COMPD_CS[\"height Z with NAD27\"," + Z
494: + "," + NAD27 + "]";
495:
496: final String WGS84_H = "COMPD_CS[\"Wgs84 with sea-level Z\","
497: + WGS84 + "," + H + "]";
498: final String NAD27_H = "COMPD_CS[\"NAD27 with sea-level Z\","
499: + NAD27 + "," + H + "]";
500:
501: CoordinateReferenceSystem sourceCRS, targetCRS;
502: CoordinateOperation op;
503: MathTransform mt;
504:
505: if (true) {
506: sourceCRS = crsFactory.createFromWKT(NAD27);
507: targetCRS = crsFactory.createFromWKT(WGS84);
508: op = opFactory.createOperation(sourceCRS, targetCRS);
509: mt = op.getMathTransform();
510: assertTrue(op instanceof Transformation);
511: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
512: assertSame(sourceCRS, op.getSourceCRS());
513: assertSame(targetCRS, op.getTargetCRS());
514: }
515: assertFalse(mt.isIdentity());
516: assertInterfaced(mt);
517: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
518: // Note: Expected values below were computed with Geotools (not an external library).
519: // However, it was tested with both Molodenski and Geocentric transformations.
520: assertTransformEquals2_2(mt, 0.0, 0.0,
521: 0.001654978796746043, 0.0012755944235822696);
522: assertTransformEquals2_2(mt, 5.0, 8.0,
523: 5.001262960018587, 8.001271733843957);
524: }
525: }
526: if (true) {
527: sourceCRS = crsFactory.createFromWKT(Z);
528: targetCRS = crsFactory.createFromWKT(Z);
529: op = opFactory.createOperation(sourceCRS, targetCRS);
530: mt = op.getMathTransform();
531: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
532: assertSame(sourceCRS, op.getSourceCRS());
533: assertSame(targetCRS, op.getTargetCRS());
534: }
535: assertTrue(op instanceof Conversion);
536: assertTrue(mt.isIdentity());
537: assertInterfaced(mt);
538: }
539: if (true) {
540: sourceCRS = crsFactory.createFromWKT(H);
541: targetCRS = crsFactory.createFromWKT(H);
542: op = opFactory.createOperation(sourceCRS, targetCRS);
543: mt = op.getMathTransform();
544: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
545: assertSame(sourceCRS, op.getSourceCRS());
546: assertSame(targetCRS, op.getTargetCRS());
547: }
548: assertTrue(op instanceof Conversion);
549: assertTrue(mt.isIdentity());
550: assertInterfaced(mt);
551: }
552: if (true)
553: try {
554: sourceCRS = crsFactory.createFromWKT(Z);
555: targetCRS = crsFactory.createFromWKT(H);
556: op = opFactory.createOperation(sourceCRS, targetCRS);
557: fail();
558: } catch (OperationNotFoundException exception) {
559: // This is the expected exception.
560: }
561: if (true) {
562: sourceCRS = crsFactory.createFromWKT(NAD27_Z);
563: targetCRS = crsFactory.createFromWKT(WGS84_Z);
564: op = opFactory.createOperation(sourceCRS, targetCRS);
565: mt = op.getMathTransform();
566: assertNotSame(sourceCRS, op.getSourceCRS());
567: assertNotSame(targetCRS, op.getTargetCRS());
568: assertTrue(op instanceof Transformation);
569: assertTrue(sourceCRS instanceof CompoundCRS);
570: assertTrue(op.getSourceCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D
571: assertTrue(targetCRS instanceof CompoundCRS);
572: assertTrue(op.getTargetCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D
573: assertFalse(sourceCRS.equals(targetCRS));
574: assertFalse(op.getSourceCRS().equals(op.getTargetCRS()));
575: assertFalse(mt.isIdentity());
576: assertInterfaced(mt);
577: // Note: Expected values below were computed with Geotools (not an external library).
578: // However, it was tested with both Molodenski and Geocentric transformations.
579: assertTransformEquals3_3(mt, 0, 0, 0, 0.001654978796746043,
580: 0.0012755944235822696, 66.4042236590758);
581: assertTransformEquals3_3(mt, 5, 8, 20, 5.0012629560319874,
582: 8.001271729856333, 120.27929787151515);
583: assertTransformEquals3_3(mt, 5, 8, -20, 5.001262964005206,
584: 8.001271737831601, 80.2792978901416);
585: assertTransformEquals3_3(mt, -5, -8, -20,
586: -4.99799698932651, -7.998735783965731,
587: 9.007854541763663);
588: }
589: if (true) {
590: sourceCRS = crsFactory.createFromWKT(Z_NAD27);
591: targetCRS = crsFactory.createFromWKT(WGS84_Z);
592: op = opFactory.createOperation(sourceCRS, targetCRS);
593: mt = op.getMathTransform();
594: assertNotSame(sourceCRS, op.getSourceCRS());
595: assertNotSame(targetCRS, op.getTargetCRS());
596: assertTrue(op instanceof Transformation);
597: assertTrue(sourceCRS instanceof CompoundCRS);
598: assertTrue(op.getSourceCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D
599: assertTrue(targetCRS instanceof CompoundCRS);
600: assertTrue(op.getTargetCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D
601: assertFalse(sourceCRS.equals(targetCRS));
602: assertFalse(op.getSourceCRS().equals(op.getTargetCRS()));
603: assertFalse(mt.isIdentity());
604: assertInterfaced(mt);
605: // Note: Expected values below were computed with Geotools (not an external library).
606: // However, it was tested with both Molodenski and Geocentric transformations.
607: assertTransformEquals3_3(mt, 0, 0, 0, 0.001654978796746043,
608: 0.0012755944235822696, 66.4042236590758);
609: assertTransformEquals3_3(mt, -20, 5, 8, 5.001262964005206,
610: 8.001271737831601, 80.2792978901416);
611: }
612: if (true) {
613: sourceCRS = crsFactory.createFromWKT(NAD27_Z);
614: targetCRS = crsFactory.createFromWKT(WGS84);
615: op = opFactory.createOperation(sourceCRS, targetCRS);
616: mt = op.getMathTransform();
617: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
618: assertNotSame(sourceCRS, op.getSourceCRS());
619: assertSame(targetCRS, op.getTargetCRS());
620: }
621: assertFalse(mt.isIdentity());
622: assertInterfaced(mt);
623: // Note: Expected values below were computed with Geotools (not an external library).
624: // However, it was tested with both Molodenski and Geocentric transformations.
625: assertTransformEquals3_2(mt, 0, 0, 0, 0.001654978796746043,
626: 0.0012755944235822696);
627: assertTransformEquals3_2(mt, 5, 8, 20, 5.0012629560319874,
628: 8.001271729856333);
629: assertTransformEquals3_2(mt, 5, 8, -20, 5.001262964005206,
630: 8.001271737831601);
631: }
632: if (true) {
633: sourceCRS = crsFactory.createFromWKT(NAD27_Z);
634: targetCRS = crsFactory.createFromWKT(Z);
635: op = opFactory.createOperation(sourceCRS, targetCRS);
636: mt = op.getMathTransform();
637: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
638: assertSame(sourceCRS, op.getSourceCRS());
639: assertSame(targetCRS, op.getTargetCRS());
640: }
641: assertFalse(mt.isIdentity());
642: assertInterfaced(mt);
643: assertTransformEquals3_1(mt, 0, 0, 0, 0);
644: assertTransformEquals3_1(mt, 5, 8, 20, 20);
645: assertTransformEquals3_1(mt, -5, -8, 20, 20);
646: }
647: if (true) {
648: sourceCRS = crsFactory.createFromWKT(NAD27);
649: targetCRS = crsFactory.createFromWKT(WGS84_Z);
650: op = opFactory.createOperation(sourceCRS, targetCRS);
651: mt = op.getMathTransform();
652: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
653: assertSame(sourceCRS, op.getSourceCRS());
654: assertNotSame(targetCRS, op.getTargetCRS());
655: }
656: assertFalse(mt.isIdentity());
657: assertInterfaced(mt);
658: // Note: Expected values below were computed with Geotools (not an external library).
659: // However, it was tested with both Molodenski and Geocentric transformations.
660: assertTransformEquals2_3(mt, 0, 0, 0.001654978796746043,
661: 0.0012755944235822696, 66.4042236590758);
662: assertTransformEquals2_3(mt, 5, 8, 5.001262960018587,
663: 8.001271733843957, 100.27929787896574);
664: }
665: if (true)
666: try {
667: sourceCRS = crsFactory.createFromWKT(NAD27_H);
668: targetCRS = crsFactory.createFromWKT(NAD27_Z);
669: op = opFactory.createOperation(sourceCRS, targetCRS);
670: mt = op.getMathTransform();
671: assertNotSame(sourceCRS, op.getSourceCRS());
672: assertNotSame(targetCRS, op.getTargetCRS());
673: assertFalse(mt.isIdentity());
674: assertInterfaced(mt);
675: fail("Should fails unless GEOT-352 has been fixed");
676: } catch (OperationNotFoundException exception) {
677: // This is the expected exception.
678: }
679: if (true)
680: try {
681: sourceCRS = crsFactory.createFromWKT(NAD27_H);
682: targetCRS = crsFactory.createFromWKT(WGS84_H);
683: op = opFactory.createOperation(sourceCRS, targetCRS);
684: mt = op.getMathTransform();
685: assertNotSame(sourceCRS, op.getSourceCRS());
686: assertNotSame(targetCRS, op.getTargetCRS());
687: assertFalse(mt.isIdentity());
688: assertInterfaced(mt);
689: fail("Should fails unless GEOT-352 has been fixed");
690: } catch (OperationNotFoundException exception) {
691: // This is the expected exception.
692: }
693: if (true)
694: try {
695: sourceCRS = crsFactory.createFromWKT(NAD27);
696: targetCRS = crsFactory.createFromWKT(WGS84_H);
697: op = opFactory.createOperation(sourceCRS, targetCRS);
698: mt = op.getMathTransform();
699: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
700: assertSame(sourceCRS, op.getSourceCRS());
701: assertNotSame(targetCRS, op.getTargetCRS());
702: }
703: assertFalse(mt.isIdentity());
704: assertInterfaced(mt);
705: fail("Should fails unless GEOT-352 has been fixed");
706: } catch (OperationNotFoundException exception) {
707: // This is the expected exception.
708: }
709: if (true) {
710: sourceCRS = crsFactory.createFromWKT(NAD27_H);
711: targetCRS = crsFactory.createFromWKT(H);
712: op = opFactory.createOperation(sourceCRS, targetCRS);
713: mt = op.getMathTransform();
714: if (!(opFactory instanceof AuthorityBackedFactory)) { // See comment in class javadoc
715: assertSame(sourceCRS, op.getSourceCRS());
716: assertSame(targetCRS, op.getTargetCRS());
717: }
718: assertFalse(mt.isIdentity());
719: assertInterfaced(mt);
720: assertTransformEquals3_1(mt, 0, 0, 0, 0);
721: assertTransformEquals3_1(mt, 5, 8, 20, 20);
722: assertTransformEquals3_1(mt, -5, -8, 20, 20);
723: }
724: }
725: }
|