01: /*
02: * Geotools2 - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002, 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;
09: * version 2.1 of the License.
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: */
17: package org.geotools.gce.gtopo30;
18:
19: import java.io.File;
20: import java.net.URL;
21:
22: import javax.media.jai.JAI;
23: import javax.media.jai.TileCache;
24:
25: import org.geotools.coverage.grid.GridCoverage2D;
26: import org.geotools.coverage.grid.io.AbstractGridFormat;
27: import org.geotools.resources.TestData;
28: import org.opengis.coverage.grid.GridCoverageReader;
29: import org.opengis.coverage.grid.GridCoverageWriter;
30: import org.opengis.parameter.GeneralParameterValue;
31: import org.opengis.parameter.ParameterValueGroup;
32:
33: /**
34: * Purpose of this method is testing the ability of this plugin to write the
35: * complete set of files for the GTOPO30 format in a single zip package.
36: *
37: * @author Simone Giannecchini
38: * @source $URL:
39: */
40: public class GT30ZipWriterTest extends GT30TestBase {
41: /**
42: * DOCUMENT ME!
43: *
44: * @param name
45: */
46: public GT30ZipWriterTest(String name) {
47: super (name);
48: }
49:
50: /**
51: * Testing zipped-package writing capabilites.
52: *
53: * @throws Exception
54: */
55: public void test() throws Exception {
56: final URL statURL = TestData.getResource(this , this .fileName
57: + ".DEM");
58: final AbstractGridFormat format = (AbstractGridFormat) new GTopo30FormatFactory()
59: .createFormat();
60:
61: final TileCache defaultInstance = JAI.getDefaultInstance()
62: .getTileCache();
63: defaultInstance.setMemoryCapacity(1024 * 1024 * 64);
64: defaultInstance.setMemoryThreshold(1.0f);
65:
66: final GTopo30WriteParams wp = new GTopo30WriteParams();
67: wp.setCompressionMode(GTopo30WriteParams.MODE_EXPLICIT);
68: wp.setCompressionType("ZIP");
69: ParameterValueGroup params = format.getWriteParameters();
70: params.parameter(
71: AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName()
72: .toString()).setValue(wp);
73:
74: if (format.accepts(statURL)) {
75: // get a reader
76: final GridCoverageReader reader = format.getReader(statURL);
77:
78: // get a grid coverage
79: final GridCoverage2D gc = ((GridCoverage2D) reader
80: .read(null));
81:
82: // preparing to write it down
83: File testDir = TestData.file(this , "");
84: newDir = new File(testDir.getAbsolutePath() + "/newDir");
85: newDir.mkdir();
86:
87: final GridCoverageWriter writer = format.getWriter(newDir);
88: writer.write(gc, (GeneralParameterValue[]) params.values()
89: .toArray(new GeneralParameterValue[1]));
90:
91: gc.dispose();
92: }
93: }
94:
95: public static final void main(String[] args) throws Exception {
96: junit.textui.TestRunner.run((GT30ZipWriterTest.class));
97: }
98: }
|