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.io;
018:
019: // J2SE dependencies and extensions
020: import java.awt.Color;
021: import java.awt.geom.Rectangle2D;
022: import java.awt.image.RenderedImage;
023: import java.io.File;
024: import java.io.IOException;
025: import javax.imageio.ImageIO;
026: import junit.framework.Assert;
027:
028: // OpenGIS and Geotools dependencies
029: import org.opengis.referencing.crs.CoordinateReferenceSystem;
030: import org.geotools.referencing.crs.DefaultGeographicCRS;
031: import org.geotools.coverage.Category;
032: import org.geotools.coverage.FactoryFinder;
033: import org.geotools.coverage.GridSampleDimension;
034: import org.geotools.coverage.grid.GridCoverage2D;
035: import org.geotools.coverage.grid.GridCoverageFactory;
036: import org.geotools.geometry.GeneralEnvelope;
037: import org.geotools.test.TestData;
038: import org.geotools.util.NumberRange;
039:
040: /**
041: * A factory for sample {@link GridCoverage2D}, which may be used for tests
042: * in other modules. This factory is a trimmed copy of a class of the same
043: * name in the {@code coverage} module. We made this copy because we currently
044: * can't leverage test classes defined in an other module.
045: *
046: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/test/java/org/geotools/coverage/io/GridCoverageExamples.java $
047: * @version $Id: GridCoverageExamples.java 25592 2007-05-20 10:51:40Z desruisseaux $
048: * @author Martin Desruisseaux
049: */
050: public final class GridCoverageExamples extends Assert {
051: /**
052: * Do not allows instantiation of this class.
053: */
054: private GridCoverageExamples() {
055: }
056:
057: /**
058: * Returns the number of available image which may be used as example.
059: */
060: public static int getNumExamples() {
061: return 1;
062: }
063:
064: /**
065: * Returns a {@link GridCoverage} which may be used as a "real world" example.
066: *
067: * @param number The example number. Numbers are numeroted from
068: * 0 to {@link #getNumExamples()} exclusive.
069: * @return The "real world" grid coverage.
070: * @throws IOException if an I/O operation was needed and failed.
071: */
072: public static GridCoverage2D getExample(final int number)
073: throws IOException {
074: final GridCoverageFactory factory = FactoryFinder
075: .getGridCoverageFactory(null);
076: final String path;
077: final Category[] categories;
078: final CoordinateReferenceSystem crs;
079: final Rectangle2D bounds;
080: final GridSampleDimension[] bands;
081: switch (number) {
082: default: {
083: throw new IllegalArgumentException(String.valueOf(number));
084: }
085: case 0: {
086: //unit = "°C";
087: path = "QL95209.png";
088: crs = DefaultGeographicCRS.WGS84;
089: categories = new Category[] {
090: new Category("Coast line", Color.decode("#000000"),
091: new NumberRange(0, 0)),
092: new Category("Cloud", Color.decode("#C3C3C3"),
093: new NumberRange(1, 9)),
094: new Category("Unused", Color.decode("#822382"),
095: new NumberRange(10, 29)),
096: new Category("Sea Surface Temperature", null,
097: new NumberRange(30, 219), 0.1, 10.0),
098: new Category("Unused", Color.decode("#A0505C"),
099: new NumberRange(220, 239)),
100: new Category("Land", Color.decode("#D2C8A0"),
101: new NumberRange(240, 254)),
102: new Category("No data", Color.decode("#FFFFFF"),
103: new NumberRange(255, 255)), };
104: // 41°S - 5°N ; 35°E - 80°E (450 x 460 pixels)
105: bounds = new Rectangle2D.Double(35, -41, 45, 46);
106: bands = new GridSampleDimension[] { new GridSampleDimension(
107: "Measure", categories, null) };
108: break;
109: }
110: }
111: final GeneralEnvelope envelope = new GeneralEnvelope(bounds);
112: final RenderedImage image = ImageIO.read(TestData.getResource(
113: GridCoverage2D.class, path));
114: final String filename = new File(path).getName();
115: envelope.setCoordinateReferenceSystem(crs);
116: return (GridCoverage2D) factory.create(filename, image,
117: envelope, bands, null, null);
118: }
119: }
|