Source Code Cross Referenced for PredefinedObjectsTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » referencing » 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 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2004-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2004, 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;
018:
019:        // J2SE dependencies and extensions
020:        import java.io.ByteArrayInputStream;
021:        import java.io.ByteArrayOutputStream;
022:        import java.io.IOException;
023:        import java.io.ObjectInputStream;
024:        import java.io.ObjectOutputStream;
025:        import java.util.HashMap;
026:        import java.util.Locale;
027:        import java.util.Map;
028:        import javax.units.SI;
029:
030:        // JUnit dependencies
031:        import junit.framework.Test;
032:        import junit.framework.TestCase;
033:        import junit.framework.TestSuite;
034:
035:        // OpenGIS dependencies
036:        import org.opengis.referencing.datum.VerticalDatumType;
037:        import org.opengis.util.GenericName;
038:
039:        // Geotools dependencies
040:        import org.geotools.referencing.crs.AbstractCRS;
041:        import org.geotools.referencing.crs.DefaultGeographicCRS;
042:        import org.geotools.referencing.cs.AbstractCS;
043:        import org.geotools.referencing.cs.DefaultCartesianCS;
044:        import org.geotools.referencing.cs.DefaultCoordinateSystemAxis;
045:        import org.geotools.referencing.cs.DefaultEllipsoidalCS;
046:        import org.geotools.referencing.cs.DefaultTimeCS;
047:        import org.geotools.referencing.cs.DefaultVerticalCS;
048:        import org.geotools.referencing.datum.AbstractDatum;
049:        import org.geotools.referencing.datum.DefaultEllipsoid;
050:        import org.geotools.referencing.datum.DefaultGeodeticDatum;
051:        import org.geotools.referencing.datum.DefaultPrimeMeridian;
052:        import org.geotools.referencing.datum.DefaultVerticalDatum;
053:
054:        /**
055:         * Tests <cite>Well Know Text</cite> (WKT) formatting for some hard-coded, predefined objects.
056:         *
057:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/PredefinedObjectsTest.java $
058:         * @version $Id: PredefinedObjectsTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
059:         * @author Martin Desruisseaux
060:         */
061:        public final class PredefinedObjectsTest extends TestCase {
062:            /**
063:             * Run the suite from the command line.
064:             */
065:            public static void main(String[] args) {
066:                org.geotools.util.logging.Logging.GEOTOOLS
067:                        .forceMonolineConsoleOutput();
068:                junit.textui.TestRunner.run(suite());
069:            }
070:
071:            /**
072:             * Returns the test suite.
073:             */
074:            public static Test suite() {
075:                return new TestSuite(PredefinedObjectsTest.class);
076:            }
077:
078:            /**
079:             * Construct a test case.
080:             */
081:            public PredefinedObjectsTest(String testName) {
082:                super (testName);
083:            }
084:
085:            /**
086:             * Tests {@link DefaultCoordinateSystemAxis} constants.
087:             */
088:            public void testAxis() {
089:                // Test Well Know Text
090:                assertEquals("x", "AXIS[\"x\", EAST]",
091:                        DefaultCoordinateSystemAxis.X.toWKT(0));
092:                assertEquals("y", "AXIS[\"y\", NORTH]",
093:                        DefaultCoordinateSystemAxis.Y.toWKT(0));
094:                assertEquals("z", "AXIS[\"z\", UP]",
095:                        DefaultCoordinateSystemAxis.Z.toWKT(0));
096:                assertEquals("Longitude", "AXIS[\"Longitude\", EAST]",
097:                        DefaultCoordinateSystemAxis.LONGITUDE.toWKT(0));
098:                assertEquals("Latitude", "AXIS[\"Latitude\", NORTH]",
099:                        DefaultCoordinateSystemAxis.LATITUDE.toWKT(0));
100:                assertEquals("Altitude", "AXIS[\"Altitude\", UP]",
101:                        DefaultCoordinateSystemAxis.ALTITUDE.toWKT(0));
102:                assertEquals("Time", "AXIS[\"Time\", FUTURE]",
103:                        DefaultCoordinateSystemAxis.TIME.toWKT(0));
104:
105:                assertEquals("Longitude", "AXIS[\"Geodetic longitude\", EAST]",
106:                        DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE.toWKT(0));
107:                assertEquals("Longitude",
108:                        "AXIS[\"Spherical longitude\", EAST]",
109:                        DefaultCoordinateSystemAxis.SPHERICAL_LONGITUDE
110:                                .toWKT(0));
111:                assertEquals("Latitude", "AXIS[\"Geodetic latitude\", NORTH]",
112:                        DefaultCoordinateSystemAxis.GEODETIC_LATITUDE.toWKT(0));
113:                assertEquals("Latitude", "AXIS[\"Spherical latitude\", NORTH]",
114:                        DefaultCoordinateSystemAxis.SPHERICAL_LATITUDE.toWKT(0));
115:
116:                // Test localization
117:                assertEquals("English", "Time",
118:                        ((GenericName) DefaultCoordinateSystemAxis.TIME
119:                                .getAlias().iterator().next())
120:                                .toInternationalString().toString(
121:                                        Locale.ENGLISH));
122:                assertEquals("French", "Temps",
123:                        ((GenericName) DefaultCoordinateSystemAxis.TIME
124:                                .getAlias().iterator().next())
125:                                .toInternationalString()
126:                                .toString(Locale.FRENCH));
127:                // TODO: remove cast and use static import once we are allowed to compile for J2SE 1.5.
128:                //       It will make the line much shorter!!
129:
130:                // Test geocentric
131:                assertFalse("X", DefaultCoordinateSystemAxis.X.equals(
132:                        DefaultCoordinateSystemAxis.GEOCENTRIC_X, false));
133:                assertFalse("Longitude", DefaultCoordinateSystemAxis.LONGITUDE
134:                        .equals(DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE,
135:                                true));
136:                assertFalse(
137:                        "Longitude",
138:                        DefaultCoordinateSystemAxis.LONGITUDE
139:                                .equals(
140:                                        DefaultCoordinateSystemAxis.SPHERICAL_LONGITUDE,
141:                                        true));
142:                assertFalse(
143:                        "Longitude",
144:                        DefaultCoordinateSystemAxis.LONGITUDE
145:                                .equals(
146:                                        DefaultCoordinateSystemAxis.SPHERICAL_LONGITUDE,
147:                                        false));
148:
149:                // Test aliases in the special "longitude" and "latitude" cases.
150:                assertTrue("Longitude", DefaultCoordinateSystemAxis.LONGITUDE
151:                        .equals(DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE,
152:                                false));
153:                assertTrue("Latitude", DefaultCoordinateSystemAxis.LATITUDE
154:                        .equals(DefaultCoordinateSystemAxis.GEODETIC_LATITUDE,
155:                                false));
156:                assertFalse("Lon/Lat", DefaultCoordinateSystemAxis.LATITUDE
157:                        .equals(DefaultCoordinateSystemAxis.LONGITUDE, false));
158:            }
159:
160:            /**
161:             * Tests {@link AbstractCS}.
162:             */
163:            public void testCoordinateSystems() {
164:                // Test dimensions
165:                assertEquals("Cartesian 2D", 2, DefaultCartesianCS.PROJECTED
166:                        .getDimension());
167:                assertEquals("Cartesian 3D", 3, DefaultCartesianCS.GEOCENTRIC
168:                        .getDimension());
169:                assertEquals("Ellipsoidal 2D", 2,
170:                        DefaultEllipsoidalCS.GEODETIC_2D.getDimension());
171:                assertEquals("Ellipsoidal 3D", 3,
172:                        DefaultEllipsoidalCS.GEODETIC_3D.getDimension());
173:                assertEquals("Vertical", 1, DefaultVerticalCS.DEPTH
174:                        .getDimension());
175:                assertEquals("Temporal", 1, DefaultTimeCS.DAYS.getDimension());
176:            }
177:
178:            /**
179:             * Test {@link AbstractDatum} and well-know text formatting.
180:             */
181:            public void testDatum() {
182:                // WGS84 components and equalities
183:                assertEquals("Ellipsoid", DefaultEllipsoid.WGS84,
184:                        DefaultGeodeticDatum.WGS84.getEllipsoid());
185:                assertEquals("PrimeMeridian", DefaultPrimeMeridian.GREENWICH,
186:                        DefaultGeodeticDatum.WGS84.getPrimeMeridian());
187:                assertFalse("VerticalDatum", DefaultVerticalDatum.GEOIDAL
188:                        .equals(DefaultVerticalDatum.ELLIPSOIDAL));
189:                assertEquals("Geoidal", VerticalDatumType.GEOIDAL,
190:                        DefaultVerticalDatum.GEOIDAL.getVerticalDatumType());
191:                assertEquals("Ellipsoidal", VerticalDatumType.ELLIPSOIDAL,
192:                        DefaultVerticalDatum.ELLIPSOIDAL.getVerticalDatumType());
193:
194:                // Test WKT
195:                assertEquals("Ellipsoid",
196:                        "SPHEROID[\"WGS84\", 6378137.0, 298.257223563]",
197:                        DefaultEllipsoid.WGS84.toWKT(0));
198:                assertEquals("PrimeMeridian", "PRIMEM[\"Greenwich\", 0.0]",
199:                        DefaultPrimeMeridian.GREENWICH.toWKT(0));
200:                assertEquals("VerticalDatum", "VERT_DATUM[\"Geoidal\", 2005]",
201:                        DefaultVerticalDatum.GEOIDAL.toWKT(0));
202:                assertEquals("VerticalDatum",
203:                        "VERT_DATUM[\"Ellipsoidal\", 2002]",
204:                        DefaultVerticalDatum.ELLIPSOIDAL.toWKT(0));
205:                assertEquals("GeodeticDatum", "DATUM[\"WGS84\", "
206:                        + "SPHEROID[\"WGS84\", 6378137.0, 298.257223563]]",
207:                        DefaultGeodeticDatum.WGS84.toWKT(0));
208:
209:                // Test properties
210:                final Map properties = new HashMap();
211:                properties.put("name", "This is a name");
212:                properties.put("scope", "This is a scope");
213:                properties.put("scope_fr", "Valide dans ce domaine");
214:                properties.put("remarks", "There is remarks");
215:                properties.put("remarks_fr", "Voici des remarques");
216:
217:                DefaultGeodeticDatum datum = new DefaultGeodeticDatum(
218:                        properties, DefaultEllipsoid.createEllipsoid("Test",
219:                                1000, 1000, SI.METER),
220:                        new DefaultPrimeMeridian("Test", 12));
221:
222:                assertEquals("name", "This is a name", datum.getName()
223:                        .getCode());
224:                assertEquals("scope", "This is a scope", datum.getScope()
225:                        .toString(null));
226:                assertEquals("scope_fr", "Valide dans ce domaine", datum
227:                        .getScope().toString(Locale.FRENCH));
228:                assertEquals("remarks", "There is remarks", datum.getRemarks()
229:                        .toString(null));
230:                assertEquals("remarks_fr", "Voici des remarques", datum
231:                        .getRemarks().toString(Locale.FRENCH));
232:            }
233:
234:            /**
235:             * Tests {@link AbstractCRS}.
236:             */
237:            public void testCoordinateReferenceSystems() {
238:                // Test dimensions
239:                assertEquals("WGS84 2D", 2, DefaultGeographicCRS.WGS84
240:                        .getCoordinateSystem().getDimension());
241:                assertEquals("WGS84 3D", 3, DefaultGeographicCRS.WGS84_3D
242:                        .getCoordinateSystem().getDimension());
243:
244:                // Test WKT
245:                assertEquals("WGS84", "GEOGCS[\"WGS84\", "
246:                        + "DATUM[\"WGS84\", "
247:                        + "SPHEROID[\"WGS84\", 6378137.0, 298.257223563]], "
248:                        + "PRIMEM[\"Greenwich\", 0.0], "
249:                        + "UNIT[\"degree\", 0.017453292519943295], "
250:                        + "AXIS[\"Geodetic longitude\", EAST], "
251:                        + "AXIS[\"Geodetic latitude\", NORTH]]",
252:                        DefaultGeographicCRS.WGS84.toWKT(0));
253:            }
254:
255:            /**
256:             * Test serialization of various objects.
257:             */
258:            public void testSerialization() throws IOException,
259:                    ClassNotFoundException {
260:                serialize(DefaultCoordinateSystemAxis.X);
261:                serialize(DefaultCoordinateSystemAxis.GEOCENTRIC_X);
262:                serialize(DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE);
263:                serialize(DefaultCartesianCS.PROJECTED);
264:                serialize(DefaultCartesianCS.GEOCENTRIC);
265:                serialize(DefaultEllipsoidalCS.GEODETIC_2D);
266:                serialize(DefaultEllipsoidalCS.GEODETIC_3D);
267:                serialize(DefaultGeodeticDatum.WGS84);
268:                serialize(DefaultPrimeMeridian.GREENWICH);
269:            }
270:
271:            /**
272:             * Test the serialization of the given object.
273:             */
274:            private static void serialize(final Object object)
275:                    throws IOException, ClassNotFoundException {
276:                final ByteArrayOutputStream out = new ByteArrayOutputStream();
277:                final ObjectOutputStream outs = new ObjectOutputStream(out);
278:                outs.writeObject(object);
279:                outs.close();
280:
281:                final ObjectInputStream in = new ObjectInputStream(
282:                        new ByteArrayInputStream(out.toByteArray()));
283:                final Object test = in.readObject();
284:                in.close();
285:
286:                assertEquals("Serialization", object, test);
287:                assertEquals("Serialization", object.hashCode(), test
288:                        .hashCode());
289:            }
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.