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


001:        /*
002:         *    Geotools2 - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002, Geotools Project Managment Committee (PMC)
005:         *
006:         *    This library is free software; you can redistribute it and/or
007:         *    modify it under the terms of the GNU Lesser General Public
008:         *    License as published by the Free Software Foundation;
009:         *    version 2.1 of the License.
010:         *
011:         *    This library is distributed in the hope that it will be useful,
012:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *    Lesser General Public License for more details.
015:         *
016:         */
017:        package org.geotools.gce.image;
018:
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.net.MalformedURLException;
022:        import java.net.URL;
023:        import java.text.ParseException;
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:        import java.util.List;
027:        import java.util.logging.Logger;
028:
029:        import junit.textui.TestRunner;
030:
031:        import org.geotools.coverage.grid.GridCoverage2D;
032:        import org.geotools.test.TestData;
033:        import org.opengis.coverage.grid.Format;
034:        import org.opengis.parameter.GeneralParameterValue;
035:        import org.opengis.parameter.ParameterValueGroup;
036:        import org.opengis.referencing.FactoryException;
037:        import org.opengis.referencing.operation.TransformException;
038:
039:        /**
040:         * Test class for WorldImageWriter. This test tries to read, writer and re-read
041:         * successive images checking for errors.
042:         * 
043:         * @author Simone Giannecchini
044:         * @author rgould
045:         * @source $URL:
046:         *         http://svn.geotools.org/geotools/trunk/gt/modules/plugin/image/src/test/java/org/geotools/gce/image/WorldImageWriterTest.java $
047:         */
048:        public class WorldImageWriterTest extends WorldImageBaseTestCase {
049:            private final static String[] supportedFormat = new String[] {
050:                    "tiff", "gif", "png", "bmp", "jpeg" };
051:
052:            private Logger logger = org.geotools.util.logging.Logging
053:                    .getLogger(WorldImageWriterTest.class.toString());
054:
055:            /** The format for the image e will write. */
056:            private String format;
057:
058:            public WorldImageWriterTest(String name) {
059:                super (name);
060:            }
061:
062:            protected void setUp() throws Exception {
063:                super .setUp();
064:                File testData = TestData.file(this , ".");
065:                new File(testData, "write").mkdir();
066:            }
067:
068:            /**
069:             * This method simply read all the respecting a predefined pattern inside
070:             * the testData directory and then it tries to read, write and re-read them
071:             * back. All the possible errors are caught.
072:             * 
073:             * @throws MalformedURLException
074:             * @throws IOException
075:             * @throws IllegalArgumentException
076:             * @throws FactoryException
077:             * @throws TransformException
078:             * @throws ParseException
079:             * @throws ParseException
080:             */
081:            public void testWrite() throws MalformedURLException, IOException,
082:                    IllegalArgumentException, FactoryException,
083:                    TransformException, ParseException {
084:
085:                // checking test data directory for all kind of inputs
086:                final File test_data_dir = TestData.file(this , null);
087:                final String[] fileList = test_data_dir
088:                        .list(new MyFileFilter());
089:                final int length = fileList.length;
090:                final int numSupportedFormat = supportedFormat.length;
091:                for (int j = 0; j < numSupportedFormat; j++) {
092:                    format = supportedFormat[j];
093:                    final StringBuffer buff = new StringBuffer("Format is ")
094:                            .append(format).append("\n");
095:                    for (int i = 0; i < length; i++) {
096:                        buff.append(" file is ").append(fileList[i]).append(
097:                                "\n");
098:                        // url
099:                        final URL url = TestData.getResource(this , fileList[i]);
100:                        assertTrue(url != null);
101:                        this .write(url);
102:
103:                        // getting file
104:                        final File file = TestData.file(this , fileList[i]);
105:                        assertTrue(file != null);
106:                        // starting write test
107:                        this .write(file);
108:
109:                    }
110:                    logger.info(buff.toString());
111:                }
112:
113:            }
114:
115:            /**
116:             * This method is responsible for loading the provided source object as a
117:             * cverage then for writing it on the temp directoy and finally for
118:             * rereading the coverage back into memory in order to display it.
119:             * 
120:             * @param source
121:             *            Object The object on disk representing the coverage to test.
122:             * 
123:             * @throws IOException
124:             * @throws IllegalArgumentException
125:             * @throws FactoryException
126:             * @throws TransformException
127:             * @throws ParseException
128:             */
129:            private void write(Object source) throws IOException,
130:                    IllegalArgumentException, FactoryException,
131:                    TransformException, ParseException {
132:                // instantiating a reader
133:                WorldImageReader wiReader = new WorldImageReader(source);
134:
135:                // reading the original coverage
136:                GridCoverage2D coverage = (GridCoverage2D) wiReader.read(null);
137:
138:                assertNotNull(coverage);
139:                assertNotNull(coverage.getRenderedImage());
140:                assertNotNull(coverage.getEnvelope());
141:
142:                // remember to provide a valid name, it wil be mde unique by the helper
143:                // function temp
144:                final StringBuffer buff = new StringBuffer("./write/temp")
145:                        .append(".").append(format);
146:                final File tempFile = TestData.temp(this , buff.toString());
147:
148:                // getting a writer
149:                final WorldImageWriter wiWriter = new WorldImageWriter(tempFile);
150:
151:                // writing parameters for png
152:                final Format writerFormat = wiWriter.getFormat();
153:                writerFormat.getWriteParameters().parameter("Format").setValue(
154:                        format);
155:
156:                // setting write parameters
157:                ParameterValueGroup params = wiWriter.getFormat()
158:                        .getWriteParameters();
159:                params.parameter(WorldImageFormat.FORMAT.getName().toString())
160:                        .setValue(format);
161:                GeneralParameterValue[] gpv = { params
162:                        .parameter(WorldImageFormat.FORMAT.getName().toString()) };
163:                // writing
164:                wiWriter.write(coverage, gpv);
165:                wiWriter.dispose();
166:
167:                // reading again
168:                assertTrue(tempFile.exists());
169:                wiReader = new WorldImageReader(tempFile);
170:                coverage = (GridCoverage2D) wiReader.read(null);
171:
172:                // displaying the coverage
173:                if (TestData.isInteractiveTest())
174:                    coverage.show();
175:                else
176:                    coverage.getRenderedImage().getData();
177:                wiReader.dispose();
178:                coverage.dispose();
179:            }
180:
181:            /**
182:             * TestRunner for testing inside a java application. It gives us the ability
183:             * to keep windows open to inspect what happened.
184:             * 
185:             * @param args
186:             */
187:            public static void main(String[] args) {
188:                TestRunner.run(WorldImageWriterTest.class);
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.