01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.referencing.operation.projection;
17:
18: // JUnit dependencies
19: import junit.framework.Test;
20: import junit.framework.TestCase;
21: import junit.framework.TestSuite;
22:
23: // OpenGIS dependencies
24: import org.opengis.referencing.operation.TransformException;
25:
26: /**
27: * Tests the {@link NewZealandMapGrid} implementation.
28: *
29: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/operation/projection/NewZealandMapGridTest.java $
30: * @version $Id: NewZealandMapGridTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
31: * @author Justin Deoliveira
32: */
33: public final class NewZealandMapGridTest extends TestCase {
34: /**
35: * Run the suite from the command line.
36: */
37: public static void main(String[] args) {
38: org.geotools.util.logging.Logging.GEOTOOLS
39: .forceMonolineConsoleOutput();
40: junit.textui.TestRunner.run(suite());
41: }
42:
43: /**
44: * Returns the test suite.
45: */
46: public static Test suite() {
47: return new TestSuite(NewZealandMapGridTest.class);
48: }
49:
50: /**
51: * Sets of geographic coordinates to project.
52: */
53: private static final double[] GEOGRAPHIC = { 172.739194,
54: -34.444066, 172.723106, -40.512409, 169.172062, -46.651295 };
55:
56: /**
57: * Set of projected coordinates.
58: */
59: private static final double[] PROJECTED = { 2487100.638,
60: 6751049.719, 2486533.395, 6077263.661, 2216746.425,
61: 5388508.765 };
62:
63: /**
64: * Computes the forward transform and compares against the expected result.
65: */
66: public void testTransform() throws TransformException {
67: double[] dst = new double[6];
68: new NewZealandMapGrid().transform(GEOGRAPHIC, 0, dst, 0, 3);
69: for (int i = 0; i < PROJECTED.length; i++) {
70: assertEquals(PROJECTED[i], dst[i], 0.1); // 10 cm precision
71: }
72: }
73:
74: /**
75: * Computes the inverse transform and compares against the expected result.
76: */
77: public void testInverseTransform() throws TransformException {
78: double[] dst = new double[6];
79: new NewZealandMapGrid().inverse().transform(PROJECTED, 0, dst,
80: 0, 3);
81: for (int i = 0; i < GEOGRAPHIC.length; i++) {
82: assertEquals(GEOGRAPHIC[i], dst[i], 0.0001); // About 10 m precision
83: }
84: }
85:
86: /**
87: * Tests WKT formatting.
88: */
89: public void testWKT() {
90: final String wkt = new NewZealandMapGrid().toWKT();
91: assertTrue(wkt.indexOf("central_meridian") >= 0);
92: }
93: }
|