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


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.coverage.grid;
018:
019:        // J2SE dependencies
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.logging.Logger;
026:
027:        // JUnit dependencies
028:        import junit.framework.Test;
029:        import junit.framework.TestCase;
030:        import junit.framework.TestSuite;
031:
032:        // OpenGIS dependencies
033:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
034:
035:        import org.geotools.referencing.crs.DefaultGeographicCRS;
036:        import org.geotools.util.logging.Logging;
037:        import org.geotools.resources.Utilities;
038:
039:        /**
040:         * Tests the {@link GridCoverage2D} implementation.
041:         *
042:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/grid/GridCoverageTest.java $
043:         * @version $Id: GridCoverageTest.java 27862 2007-11-12 19:51:19Z desruisseaux $
044:         * @author Martin Desruisseaux
045:         */
046:        public class GridCoverageTest extends TestCase {
047:            /**
048:             * Run the suite from the command line.
049:             */
050:            public static void main(final String[] args) {
051:                junit.textui.TestRunner.run(suite());
052:            }
053:
054:            /**
055:             * Returns the test suite.
056:             */
057:            public static Test suite() {
058:                return new TestSuite(GridCoverageTest.class);
059:            }
060:
061:            /**
062:             * Constructs a test case with the given name.
063:             */
064:            public GridCoverageTest(final String name) {
065:                super (name);
066:            }
067:
068:            /**
069:             * Tests the construction and access to a grid coverage.
070:             *
071:             * @throws IOException if an I/O operation was needed and failed.
072:             */
073:            public void testGridCoverage() throws IOException {
074:                final GridCoverage2D coverage = getRandomCoverage();
075:                assertNotNull(coverage);
076:                // Not much more test to do here, since most tests has been done
077:                // inside 'getRandomCoverage'. This method will be overridden by
078:                // 'InterpolatorTest', which will perform more tests.
079:                for (int i = GridCoverageExamples.getNumExamples(); --i >= 0;) {
080:                    assertNotNull(GridCoverageExamples.getExample(i));
081:                }
082:            }
083:
084:            /**
085:             * Tests the serialization of a grid coverage.
086:             *
087:             * @throws IOException if an I/O operation was needed and failed.
088:             */
089:            public void testSerialization() throws IOException,
090:                    ClassNotFoundException {
091:                final GridCoverage2D coverage = getRandomCoverage();
092:                assertNotNull(coverage);
093:                coverage.tileEncoding = null;
094:                /*
095:                 * The previous line is not something that we should do.
096:                 * But we want to test the default GridCoverage2D encoding.
097:                 */
098:                final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
099:                final ObjectOutputStream out = new ObjectOutputStream(buffer);
100:                try {
101:                    out.writeObject(coverage.geophysics(false));
102:                    //          out.writeObject(coverage.geophysics(true ));
103:                } catch (IllegalArgumentException e) {
104:                    /*
105:                     * TODO: this exception occurs when ImageLayout contains a SampleModel or a ColorModel
106:                     *       unknow to javax.media.jai.remote.SerializerFactory getState(...) method. This
107:                     *       happen if an operation we applied on the coverage in some subclass (especially
108:                     *       OperationsTest). Ignore the exception for now, but we need to revisit this
109:                     *       issue later.
110:                     */
111:                    if (getClass().equals(GridCoverageTest.class)) {
112:                        e.printStackTrace();
113:                    }
114:                    out.close();
115:                    return;
116:                }
117:                out.close();
118:                /*
119:                 * Deserialization requires J2SE 1.5 or above.
120:                 */
121:                if (System.getProperty("java.version").compareTo("1.5") >= 0) {
122:                    final ObjectInputStream in = new ObjectInputStream(
123:                            new ByteArrayInputStream(buffer.toByteArray()));
124:                    GridCoverage2D read;
125:                    read = (GridCoverage2D) in.readObject();
126:                    assertSame(read, read.geophysics(false));
127:                    //          read = (GridCoverage2D) in.readObject(); assertSame(read, read.geophysics(true ));
128:                    //          assertNotSame(read, read.geophysics(true));
129:                    in.close();
130:                } else {
131:                    Logging
132:                            .getLogger("org.geotools.coverage.grid")
133:                            .fine(
134:                                    "Deserialization test skipped for pre-1.5 Java version.");
135:                }
136:            }
137:
138:            /**
139:             * Applies an operation on the specified coverage, if wanted. The
140:             * default implementation returns {@code coverage} with no change.
141:             */
142:            protected GridCoverage2D transform(final GridCoverage2D coverage) {
143:                return coverage;
144:            }
145:
146:            /**
147:             * Returns a grid coverage filled with random values. The coordinate
148:             * reference system default to {@link DefaultGeographicCRS#WGS84}.
149:             *
150:             * @return A random coverage.
151:             */
152:            protected GridCoverage2D getRandomCoverage() {
153:                return getRandomCoverage(DefaultGeographicCRS.WGS84);
154:            }
155:
156:            /**
157:             * Returns a grid coverage filled with random values.
158:             *
159:             * @param crs The coverage coordinate reference system.
160:             * @return A random coverage.
161:             */
162:            protected GridCoverage2D getRandomCoverage(
163:                    final CoordinateReferenceSystem crs) {
164:                final GridCoverage2D original = GridCoverageExamples
165:                        .getRandomCoverage(crs);
166:                final GridCoverage2D coverage = transform(original);
167:                /*
168:                 * Grid coverage construction finished. Now test it. Some tests will not be applicable
169:                 * if a subclass overridden the 'transform' method are returned a transformed coverage.
170:                 * We detect this case when 'coverage != original'.
171:                 */
172:                assertSame(coverage.getRenderedImage(), coverage
173:                        .getRenderableImage(0, 1).createDefaultRendering());
174:                if (!coverage.getCoordinateReferenceSystem().equals(crs)) {
175:                    assertEquals("Resampler2D", Utilities
176:                            .getShortClassName(coverage));
177:                }
178:                /*
179:                 * Tests the creation of a "geophysics" view. This test make sure that the
180:                 * 'geophysics' method do not creates more grid coverage than needed.
181:                 */
182:                GridCoverage2D geophysics = coverage.geophysics(true);
183:                assertSame(coverage, coverage.geophysics(false));
184:                assertSame(coverage, geophysics.geophysics(false));
185:                assertSame(geophysics, geophysics.geophysics(true));
186:                assertFalse(coverage.equals(geophysics));
187:                assertFalse(coverage.getSampleDimension(0)
188:                        .getSampleToGeophysics().isIdentity());
189:                assertTrue(geophysics.getSampleDimension(0)
190:                        .getSampleToGeophysics().isIdentity());
191:                return coverage;
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.