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.geotiff;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.util.logging.Logger;
022:
023: import junit.framework.TestCase;
024: import junit.textui.TestRunner;
025:
026: import org.geotools.TestData;
027: import org.geotools.coverage.grid.GridCoverage2D;
028: import org.geotools.coverage.grid.io.AbstractGridFormat;
029: import org.geotools.coverage.grid.io.imageio.IIOMetadataDumper;
030: import org.geotools.factory.Hints;
031: import org.opengis.referencing.NoSuchAuthorityCodeException;
032:
033: /*
034: * GeoTools - OpenSource mapping toolkit http://geotools.org (C) 2005-2006,
035: * GeoTools Project Managment Committee (PMC) This library is free software; you
036: * can redistribute it and/or modify it under the terms of the GNU Lesser
037: * General Public License as published by the Free Software Foundation; version
038: * 2.1 of the License. This library is distributed in the hope that it will be
039: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
040: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
041: * General Public License for more details.
042: */
043: /**
044: * Testing {@link GeoTiffReader} as well as {@link IIOMetadataDumper}.
045: *
046: * @author Simone Giannecchini
047: * @source $URL:
048: * http://svn.geotools.org/geotools/trunk/gt/plugin/geotiff/test/org/geotools/gce/geotiff/GeoTiffReaderTest.java $
049: */
050: public class GeoTiffReaderTest extends TestCase {
051: private final static Logger LOGGER = org.geotools.util.logging.Logging
052: .getLogger(GeoTiffReaderTest.class.toString());
053:
054: /**
055: * Constructor for GeoTiffReaderTest.
056: *
057: * @param arg0
058: */
059: public GeoTiffReaderTest(String arg0) {
060: super (arg0);
061: }
062:
063: public static void main(String[] args) {
064: TestRunner.run(GeoTiffReaderTest.class);
065:
066: }
067:
068: /**
069: * testReader
070: *
071: * @throws IllegalArgumentException
072: * @throws IOException
073: * @throws NoSuchAuthorityCodeException
074: */
075: public void testReader() throws IllegalArgumentException,
076: IOException, NoSuchAuthorityCodeException {
077:
078: final File file = TestData.file(GeoTiffReaderTest.class, "");
079: final File files[] = file.listFiles();
080: final int numFiles = files.length;
081: final AbstractGridFormat format = new GeoTiffFormat();
082: for (int i = 0; i < numFiles; i++) {
083: final StringBuffer buffer = new StringBuffer();
084: final String path = files[i].getAbsolutePath()
085: .toLowerCase();
086: if (!path.endsWith("tif") && !path.endsWith("tiff"))
087: continue;
088:
089: buffer.append(files[i].getAbsolutePath()).append("\n");
090: Object o;
091: if (i % 2 == 0)
092: // testing file
093: o = files[i];
094: else
095: // testing url
096: o = files[i].toURL();
097: if (format.accepts(o)) {
098: buffer.append("ACCEPTED").append("\n");
099:
100: // getting a reader
101: final GeoTiffReader reader = new GeoTiffReader(o,
102: new Hints(
103: Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
104: Boolean.TRUE));
105:
106: if (reader != null) {
107:
108: // reading the coverage
109: final GridCoverage2D coverage = (GridCoverage2D) reader
110: .read(null);
111:
112: // Crs and envelope
113: if (TestData.isInteractiveTest()) {
114: buffer
115: .append("CRS: ")
116: .append(
117: coverage
118: .getCoordinateReferenceSystem2D()
119: .toWKT()).append("\n");
120: buffer.append("Envelope: ").append(
121: coverage.getEnvelope().toString())
122: .append("\n");
123: }
124: // display metadata
125: final IIOMetadataDumper iIOMetadataDumper = new IIOMetadataDumper(
126: ((GeoTiffReader) reader).getMetadata()
127: .getRootNode());
128: buffer.append("TIFF metadata: ").append(
129: iIOMetadataDumper.getMetadata()).append(
130: "\n");
131: // showing it
132: if (TestData.isInteractiveTest())
133: coverage.show();
134: else
135: coverage.getRenderedImage().getData();
136:
137: }
138:
139: } else
140: buffer.append("NOT ACCEPTED").append("\n");
141: if (TestData.isInteractiveTest())
142: LOGGER.info(buffer.toString());
143:
144: }
145:
146: }
147: }
|