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.arcgrid;
018:
019: import java.awt.Rectangle;
020: import java.io.File;
021: import java.io.FileInputStream;
022: import java.io.IOException;
023: import java.util.zip.GZIPInputStream;
024:
025: import javax.imageio.ImageIO;
026: import javax.imageio.stream.ImageInputStream;
027:
028: import org.geotools.coverage.grid.GeneralGridRange;
029: import org.geotools.coverage.grid.GridCoverage2D;
030: import org.geotools.coverage.grid.GridGeometry2D;
031: import org.geotools.coverage.grid.io.AbstractGridFormat;
032: import org.geotools.geometry.GeneralEnvelope;
033: import org.geotools.referencing.CRS;
034: import org.geotools.test.TestData;
035: import org.geotools.resources.coverage.CoverageUtilities;
036: import org.opengis.coverage.grid.GridCoverageReader;
037: import org.opengis.parameter.GeneralParameterValue;
038: import org.opengis.parameter.ParameterValueGroup;
039:
040: /**
041: * <p>
042: * Title: TestArcGridClass
043: * </p>
044: *
045: * <p>
046: * Description: Testing ArcGrid ascii grids related classes.
047: * </p>
048: *
049: * <p>
050: * Copyright: Copyright (c) 2005 Simone Giannecchini
051: * </p>
052: *
053: * <p>
054: * Company:
055: * </p>
056: *
057: * @author <a href="mailto:simboss1@gmil.com">Simone Giannecchini (simboss)</a>
058: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/arcgrid/src/test/java/org/geotools/gce/arcgrid/ArcGridVisualizationTest.java $
059: * @version 1.0
060: */
061: public final class ArcGridVisualizationTest extends
062: ArcGridTestCaseAdapter {
063:
064: /**
065: * Creates a new instance of ArcGridReadWriteTest
066: *
067: * @param name
068: */
069: public ArcGridVisualizationTest(String name) {
070: super (name);
071:
072: }
073:
074: public static final void main(String[] args) throws Exception {
075: junit.textui.TestRunner.run(ArcGridVisualizationTest.class);
076: }
077:
078: public void testVisualization() throws Exception {
079:
080: LOGGER.info("testing visualization of precip30min.asc");
081: // read in the grid coverage
082: final GridCoverageReader reader = new ArcGridReader(TestData
083: .file(this , "arcgrid/precip30min.asc"));
084:
085: ParameterValueGroup params;
086: params = reader.getFormat().getReadParameters();
087:
088: final GeneralEnvelope envelope = new GeneralEnvelope(
089: new double[] { -180, -90 }, new double[] { 180, 90 });
090: envelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326"));
091: params.parameter(
092: AbstractGridFormat.READ_GRIDGEOMETRY2D.getName()
093: .toString()).setValue(
094: new GridGeometry2D(new GeneralGridRange(new Rectangle(
095: 0, 0, 400, 300)), envelope));
096: GeneralParameterValue[] gpv = { params
097: .parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D
098: .getName().toString()) };
099:
100: GridCoverage2D gc = (GridCoverage2D) reader.read(gpv);
101:
102: assertTrue(CoverageUtilities.hasRenderingCategories(gc));
103:
104: if (TestData.isInteractiveTest()) {
105: gc.show();
106: } else
107: gc.getRenderedImage().getData();
108: if (TestData.isInteractiveTest()) {
109: // printing CRS information
110: LOGGER.info(gc.getCoordinateReferenceSystem().toWKT());
111: LOGGER.info(gc.getEnvelope().toString());
112: }
113:
114: }
115:
116: /**
117: * This test tries to read GZipped ascii grids first by supplying the
118: * {@link ArcGridReader} with a {@link File} that points to a gzipped
119: * coverage, second by opening up a {@link GZIPInputStream} and asking
120: * {@link ImageIO} to wrap it with an {@link ImageInputStream}.
121: *
122: * @throws IOException
123: */
124: public void testReadFileGZip() throws IOException {
125: LOGGER.info("Reading the coverage through a file");
126: // get a gzipped ascii grid
127: final File f = TestData.file(this , "arcgrid/spearfish.asc.gz");
128: // Reading the coverage through a file
129: GridCoverageReader reader = new ArcGridReader(f);
130: final GridCoverage2D gc1 = (GridCoverage2D) reader.read(null);
131:
132: LOGGER
133: .info("Reading the gzipped coverage through an ImageInputStream");
134: // Reading the coverage through an ImageInputStream
135: final ImageInputStream iiStream = ImageIO
136: .createImageInputStream(new GZIPInputStream(
137: new FileInputStream(f)));
138: reader = new ArcGridReader(iiStream);
139: final GridCoverage2D gc2 = (GridCoverage2D) reader.read(null);
140:
141: LOGGER
142: .info(" Reading the gzipped coverage through an InputStream");
143: // Reading the coverage through an InputStream
144: reader = new ArcGridReader(new GZIPInputStream(
145: new FileInputStream(f)));
146: final GridCoverage2D gc3 = (GridCoverage2D) reader.read(null);
147:
148: LOGGER.info("Reading the gzipped coverage through a URL");
149: // Reading the coverage through a URL
150: reader = new ArcGridReader(f.toURL());
151: final GridCoverage2D gc4 = (GridCoverage2D) reader.read(null);
152:
153: // show the coverage or try to load the data
154: if (TestData.isInteractiveTest()) {
155: gc1.show();
156: gc2.show();
157: gc3.show();
158: gc4.show();
159: } else {
160: gc1.getRenderedImage().getData();
161: gc2.getRenderedImage().getData();
162: gc3.getRenderedImage().getData();
163: gc4.getRenderedImage().getData();
164: }
165: }
166:
167: }
|