Source Code Cross Referenced for DefaultCoordinateSystemAxisTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » referencing » cs » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.referencing.cs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2007, GeoTools Project Managment Committee (PMC)
005:         *    (C) 2007, Geomatys
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;
010:         *    version 2.1 of the License.
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.cs;
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.referencing.cs.AxisDirection;
026:
027:        /**
028:         * Tests the {@link DefaultCoordinateSystemAxis} class.
029:         *
030:         * @version $Id: DefaultCoordinateSystemAxisTest.java 25485 2007-05-11 19:12:35Z desruisseaux $
031:         * @author Martin Desruisseaux
032:         */
033:        public class DefaultCoordinateSystemAxisTest extends TestCase {
034:            /**
035:             * For floating point number comparaisons.
036:             */
037:            private static final double EPS = 1E-10;
038:
039:            /**
040:             * Run the suite from the command line.
041:             */
042:            public static void main(final String[] args) {
043:                junit.textui.TestRunner.run(suite());
044:            }
045:
046:            /**
047:             * Returns the test suite.
048:             */
049:            public static Test suite() {
050:                return new TestSuite(DefaultCoordinateSystemAxisTest.class);
051:            }
052:
053:            /**
054:             * Constructs a test case with the given name.
055:             */
056:            public DefaultCoordinateSystemAxisTest(final String name) {
057:                super (name);
058:            }
059:
060:            /**
061:             * Tests the {@link DefaultCoordinateSystemAxis#nameMatches} method.
062:             *
063:             * @todo Use "static import" when we will be allowed to compile for J2SE 1.5.
064:             */
065:            public void testNameMatches() {
066:                assertTrue(DefaultCoordinateSystemAxis.LONGITUDE
067:                        .nameMatches(DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE
068:                                .getName().getCode()));
069:                assertFalse(DefaultCoordinateSystemAxis.LONGITUDE
070:                        .nameMatches(DefaultCoordinateSystemAxis.GEODETIC_LATITUDE
071:                                .getName().getCode()));
072:                assertFalse(DefaultCoordinateSystemAxis.LONGITUDE
073:                        .nameMatches(DefaultCoordinateSystemAxis.ALTITUDE
074:                                .getName().getCode()));
075:                assertFalse(DefaultCoordinateSystemAxis.X
076:                        .nameMatches(DefaultCoordinateSystemAxis.LONGITUDE
077:                                .getName().getCode()));
078:                assertFalse(DefaultCoordinateSystemAxis.X
079:                        .nameMatches(DefaultCoordinateSystemAxis.EASTING
080:                                .getName().getCode()));
081:                assertFalse(DefaultCoordinateSystemAxis.X
082:                        .nameMatches(DefaultCoordinateSystemAxis.NORTHING
083:                                .getName().getCode()));
084:            }
085:
086:            /**
087:             * Tests the {@link DefaultCoordinateSystemAxis#getPredefined(String)} method.
088:             *
089:             * @todo Use "static import" when we will be allowed to compile for J2SE 1.5.
090:             */
091:            public void testPredefined() {
092:                assertNull(DefaultCoordinateSystemAxis.getPredefined("Dummy",
093:                        null));
094:
095:                // Tests some abbreviations shared by more than one axis.
096:                // We should get the axis with the ISO 19111 name.
097:                assertSame(DefaultCoordinateSystemAxis.GEODETIC_LATITUDE,
098:                        DefaultCoordinateSystemAxis.getPredefined("\u03C6",
099:                                null));
100:                assertSame(DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE,
101:                        DefaultCoordinateSystemAxis.getPredefined("\u03BB",
102:                                null));
103:                assertSame(DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT,
104:                        DefaultCoordinateSystemAxis.getPredefined("h", null));
105:
106:                // The following abbreviation are used by WKT parsing
107:                assertSame(DefaultCoordinateSystemAxis.GEOCENTRIC_X,
108:                        DefaultCoordinateSystemAxis.getPredefined("X",
109:                                AxisDirection.OTHER));
110:                assertSame(DefaultCoordinateSystemAxis.GEOCENTRIC_Y,
111:                        DefaultCoordinateSystemAxis.getPredefined("Y",
112:                                AxisDirection.EAST));
113:                assertSame(DefaultCoordinateSystemAxis.GEOCENTRIC_Z,
114:                        DefaultCoordinateSystemAxis.getPredefined("Z",
115:                                AxisDirection.NORTH));
116:                assertSame(DefaultCoordinateSystemAxis.LONGITUDE,
117:                        DefaultCoordinateSystemAxis.getPredefined("Lon",
118:                                AxisDirection.EAST));
119:                assertSame(DefaultCoordinateSystemAxis.LATITUDE,
120:                        DefaultCoordinateSystemAxis.getPredefined("Lat",
121:                                AxisDirection.NORTH));
122:                assertSame(DefaultCoordinateSystemAxis.X,
123:                        DefaultCoordinateSystemAxis.getPredefined("X",
124:                                AxisDirection.EAST));
125:                assertSame(DefaultCoordinateSystemAxis.Y,
126:                        DefaultCoordinateSystemAxis.getPredefined("Y",
127:                                AxisDirection.NORTH));
128:                assertSame(DefaultCoordinateSystemAxis.Z,
129:                        DefaultCoordinateSystemAxis.getPredefined("Z",
130:                                AxisDirection.UP));
131:
132:                // Tests from names
133:                assertSame(DefaultCoordinateSystemAxis.LATITUDE,
134:                        DefaultCoordinateSystemAxis.getPredefined("Latitude",
135:                                null));
136:                assertSame(DefaultCoordinateSystemAxis.LONGITUDE,
137:                        DefaultCoordinateSystemAxis.getPredefined("Longitude",
138:                                null));
139:                assertSame(DefaultCoordinateSystemAxis.GEODETIC_LATITUDE,
140:                        DefaultCoordinateSystemAxis.getPredefined(
141:                                "Geodetic latitude", null));
142:                assertSame(DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE,
143:                        DefaultCoordinateSystemAxis.getPredefined(
144:                                "Geodetic longitude", null));
145:                assertSame(DefaultCoordinateSystemAxis.NORTHING,
146:                        DefaultCoordinateSystemAxis.getPredefined("Northing",
147:                                null));
148:                assertSame(DefaultCoordinateSystemAxis.NORTHING,
149:                        DefaultCoordinateSystemAxis.getPredefined("N", null));
150:                assertSame(DefaultCoordinateSystemAxis.EASTING,
151:                        DefaultCoordinateSystemAxis.getPredefined("Easting",
152:                                null));
153:                assertSame(DefaultCoordinateSystemAxis.EASTING,
154:                        DefaultCoordinateSystemAxis.getPredefined("E", null));
155:                assertSame(DefaultCoordinateSystemAxis.SOUTHING,
156:                        DefaultCoordinateSystemAxis.getPredefined("Southing",
157:                                null));
158:                assertSame(DefaultCoordinateSystemAxis.SOUTHING,
159:                        DefaultCoordinateSystemAxis.getPredefined("S", null));
160:                assertSame(DefaultCoordinateSystemAxis.WESTING,
161:                        DefaultCoordinateSystemAxis.getPredefined("Westing",
162:                                null));
163:                assertSame(DefaultCoordinateSystemAxis.WESTING,
164:                        DefaultCoordinateSystemAxis.getPredefined("W", null));
165:                assertSame(DefaultCoordinateSystemAxis.GEOCENTRIC_X,
166:                        DefaultCoordinateSystemAxis.getPredefined("X", null));
167:                assertSame(DefaultCoordinateSystemAxis.GEOCENTRIC_Y,
168:                        DefaultCoordinateSystemAxis.getPredefined("Y", null));
169:                assertSame(DefaultCoordinateSystemAxis.GEOCENTRIC_Z,
170:                        DefaultCoordinateSystemAxis.getPredefined("Z", null));
171:                assertSame(DefaultCoordinateSystemAxis.X,
172:                        DefaultCoordinateSystemAxis.getPredefined("x", null));
173:                assertSame(DefaultCoordinateSystemAxis.Y,
174:                        DefaultCoordinateSystemAxis.getPredefined("y", null));
175:                assertSame(DefaultCoordinateSystemAxis.Z,
176:                        DefaultCoordinateSystemAxis.getPredefined("z", null));
177:            }
178:
179:            /**
180:             * Tests the {@link DefaultCoordinateSystemAxis#getPredefined(CoordinateSystemAxis)} method.
181:             */
182:            public void testPredefinedAxis() {
183:                // A few hard-coded tests for debugging convenience.
184:                assertSame(
185:                        DefaultCoordinateSystemAxis.LATITUDE,
186:                        DefaultCoordinateSystemAxis
187:                                .getPredefined(DefaultCoordinateSystemAxis.LATITUDE));
188:                assertSame(
189:                        DefaultCoordinateSystemAxis.GEODETIC_LATITUDE,
190:                        DefaultCoordinateSystemAxis
191:                                .getPredefined(DefaultCoordinateSystemAxis.GEODETIC_LATITUDE));
192:
193:                // Tests all constants.
194:                final DefaultCoordinateSystemAxis[] values = DefaultCoordinateSystemAxis
195:                        .values();
196:                for (int i = 0; i < values.length; i++) {
197:                    final DefaultCoordinateSystemAxis axis = values[i];
198:                    final String message = "values[" + i + ']';
199:                    assertNotNull(message, axis);
200:                    assertSame(message, axis, DefaultCoordinateSystemAxis
201:                            .getPredefined(axis));
202:                }
203:            }
204:
205:            /**
206:             * Makes sure that the compass directions in {@link AxisDirection} are okay.
207:             */
208:            public void testCompass() {
209:                final AxisDirection[] compass = new AxisDirection[] {
210:                        AxisDirection.NORTH, AxisDirection.NORTH_NORTH_EAST,
211:                        AxisDirection.NORTH_EAST,
212:                        AxisDirection.EAST_NORTH_EAST, AxisDirection.EAST,
213:                        AxisDirection.EAST_SOUTH_EAST,
214:                        AxisDirection.SOUTH_EAST,
215:                        AxisDirection.SOUTH_SOUTH_EAST, AxisDirection.SOUTH,
216:                        AxisDirection.SOUTH_SOUTH_WEST,
217:                        AxisDirection.SOUTH_WEST,
218:                        AxisDirection.WEST_SOUTH_WEST, AxisDirection.WEST,
219:                        AxisDirection.WEST_NORTH_WEST,
220:                        AxisDirection.NORTH_WEST,
221:                        AxisDirection.NORTH_NORTH_WEST };
222:                assertEquals(compass.length,
223:                        DefaultCoordinateSystemAxis.COMPASS_DIRECTION_COUNT);
224:                final int base = AxisDirection.NORTH.ordinal();
225:                final int h = compass.length / 2;
226:                for (int i = 0; i < compass.length; i++) {
227:                    final String index = "compass[" + i + ']';
228:                    final AxisDirection c = compass[i];
229:                    double angle = i * (360.0 / compass.length);
230:                    if (angle > 180) {
231:                        angle -= 360;
232:                    }
233:                    assertEquals(index, base + i, c.ordinal());
234:                    assertEquals(index, base + i + (i < h ? h : -h), c
235:                            .opposite().ordinal());
236:                    assertEquals(index, 0, DefaultCoordinateSystemAxis
237:                            .getAngle(c, c), EPS);
238:                    assertEquals(index, 180, Math
239:                            .abs(DefaultCoordinateSystemAxis.getAngle(c, c
240:                                    .opposite())), EPS);
241:                    assertEquals(index, angle, DefaultCoordinateSystemAxis
242:                            .getAngle(c, AxisDirection.NORTH), EPS);
243:                }
244:            }
245:
246:            /**
247:             * Tests {@link DefaultCoordinateSystemAxis#getAngle}.
248:             */
249:            public void testAngle() {
250:                assertEquals(90.0, DefaultCoordinateSystemAxis.getAngle(
251:                        AxisDirection.WEST, AxisDirection.SOUTH), EPS);
252:                assertEquals(-90.0, DefaultCoordinateSystemAxis.getAngle(
253:                        AxisDirection.SOUTH, AxisDirection.WEST), EPS);
254:                assertEquals(45.0, DefaultCoordinateSystemAxis.getAngle(
255:                        AxisDirection.SOUTH, AxisDirection.SOUTH_EAST), EPS);
256:                assertEquals(-22.5, DefaultCoordinateSystemAxis.getAngle(
257:                        AxisDirection.NORTH_NORTH_WEST, AxisDirection.NORTH),
258:                        EPS);
259:            }
260:
261:            /**
262:             * Tests {@link DefaultCoordinateSystemAxis#getAngle} using textual directions.
263:             */
264:            public void testAngle2() {
265:                compareAngle(90.0, "West", "South");
266:                compareAngle(-90.0, "South", "West");
267:                compareAngle(45.0, "South", "South-East");
268:                compareAngle(-22.5, "North-North-West", "North");
269:                compareAngle(-22.5, "North_North_West", "North");
270:                compareAngle(-22.5, "North North West", "North");
271:                compareAngle(90.0, "North along 90 deg East",
272:                        "North along 0 deg");
273:                compareAngle(90.0, "South along 180 deg",
274:                        "South along 90 deg West");
275:            }
276:
277:            /**
278:             * Compare the angle between the specified directions.
279:             */
280:            private static void compareAngle(final double expected,
281:                    final String source, final String target) {
282:                final AxisDirection dir1 = DefaultCoordinateSystemAxis
283:                        .getDirection(source);
284:                final AxisDirection dir2 = DefaultCoordinateSystemAxis
285:                        .getDirection(target);
286:                assertNotNull(dir1);
287:                assertNotNull(dir2);
288:                assertEquals(expected, DefaultCoordinateSystemAxis.getAngle(
289:                        dir1, dir2), EPS);
290:            }
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.