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.arcsde.gce;
018:
019: import java.awt.Rectangle;
020: import java.awt.image.BufferedImage;
021: import java.awt.image.RenderedImage;
022: import java.io.File;
023: import java.io.InputStream;
024: import java.net.URL;
025: import java.util.Properties;
026:
027: import javax.imageio.ImageIO;
028:
029: import junit.framework.TestCase;
030:
031: import org.geotools.arcsde.ArcSDERasterFormatFactory;
032: import org.geotools.coverage.grid.GeneralGridRange;
033: import org.geotools.coverage.grid.GridCoverage2D;
034: import org.geotools.coverage.grid.GridGeometry2D;
035: import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
036: import org.geotools.coverage.grid.io.AbstractGridFormat;
037: import org.geotools.factory.CommonFactoryFinder;
038: import org.geotools.factory.GeoTools;
039: import org.geotools.geometry.jts.ReferencedEnvelope;
040: import org.geotools.parameter.Parameter;
041: import org.geotools.referencing.CRS;
042: import org.geotools.renderer.lite.gridcoverage2d.RasterSymbolizerSupport;
043: import org.geotools.styling.NamedLayer;
044: import org.geotools.styling.RasterSymbolizer;
045: import org.geotools.styling.SLDParser;
046: import org.geotools.styling.Style;
047: import org.geotools.styling.StyledLayerDescriptor;
048: import org.opengis.coverage.grid.Format;
049: import org.opengis.parameter.GeneralParameterValue;
050: import org.opengis.referencing.crs.CoordinateReferenceSystem;
051:
052: /**
053: * Tests the functionality of the ArcSDE raster-display package to read rasters from an
054: * ArcSDE database
055: *
056: * @author Saul Farber, (based on ArcSDEPoolTest by Gabriel Roldan)
057: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/gce/ArcSDEGCReaderSymbolizedTest.java $
058: * @version $Id: ArcSDEGCReaderSymbolizedTest.java 25075 2007-04-09 19:20:46Z desruisseaux $
059: */
060: public class ArcSDEGCReaderSymbolizedTest extends TestCase {
061:
062: private CoordinateReferenceSystem crs;
063: private GridGeometry2D realWordlExampleRes;
064: private RasterSymbolizer symbolizer;
065:
066: private Properties conProps;
067:
068: /**
069: * Creates a new ArcSDEConnectionPoolTest object.
070: *
071: */
072: public ArcSDEGCReaderSymbolizedTest(String name) throws Exception {
073: super (name);
074:
075: conProps = new Properties();
076: String propsFile = "raster-testparams.properties";
077: URL conParamsSource = org.geotools.test.TestData.url(null,
078: propsFile);
079:
080: InputStream in = conParamsSource.openStream();
081: if (in == null) {
082: throw new IllegalStateException("cannot find test params: "
083: + conParamsSource.toExternalForm());
084: }
085: conProps.load(in);
086: in.close();
087: }
088:
089: public void setUp() throws Exception {
090: super .setUp();
091:
092: crs = CRS.decode("EPSG:26986");
093: realWordlExampleRes = new GridGeometry2D(new GeneralGridRange(
094: new Rectangle(256, 128)), new ReferencedEnvelope(
095: 33000.25, 330000.225, 774000.25, 983400.225, crs));
096:
097: InputStream in = org.geotools.test.TestData.url(null,
098: "testRasterStyle.sld.xml").openStream();
099: SLDParser parser = new SLDParser(CommonFactoryFinder
100: .getStyleFactory(GeoTools.getDefaultHints()));
101: parser.setInput(in);
102: StyledLayerDescriptor sld = parser.parseSLD();
103: NamedLayer layerOne = (NamedLayer) sld.getStyledLayers()[0];
104: symbolizer = (RasterSymbolizer) layerOne.getStyles()[0]
105: .getFeatureTypeStyles()[0].getRules()[0]
106: .getSymbolizers()[0];
107: }
108:
109: public void testRead3BandCoverage() throws Exception {
110:
111: String threebandurl = conProps
112: .getProperty("threebandrasterurl");
113: String fourbandurl = conProps.getProperty("fourbandrasterurl");
114:
115: GridCoverage2D gc;
116: Format f = new ArcSDERasterFormatFactory().createFormat();
117: final RasterSymbolizerSupport rsp = new RasterSymbolizerSupport(
118: symbolizer);
119: // a fix
120:
121: GeneralParameterValue[] requestParams = new Parameter[1];
122: requestParams[0] = new Parameter(
123: AbstractGridFormat.READ_GRIDGEOMETRY2D,
124: realWordlExampleRes);
125:
126: AbstractGridCoverage2DReader r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
127: .getReader(threebandurl);
128: gc = (GridCoverage2D) r.read(requestParams);
129: assertNotNull(gc);
130: //ImageIO.write(((GridCoverage2D) rsp.recolorCoverage(gc)).geophysics(true).getRenderedImage(), "PNG", new File("threeBandRecolored.png"));
131: assertTrue("Image from SDE isn't what we expected.",
132: RasterTestUtils.imageEquals(((GridCoverage2D) rsp
133: .recolorCoverage(gc)).geophysics(true)
134: .getRenderedImage(), "threeBandRecolored.png"));
135:
136: r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
137: .getReader(fourbandurl);
138: gc = (GridCoverage2D) r.read(requestParams);
139: assertNotNull(gc);
140: //ImageIO.write(((GridCoverage2D) rsp.recolorCoverage(gc)).geophysics(false).getRenderedImage(), "PNG", new File("fourBandRecolored.png"));
141: assertTrue("Image from SDE isn't what we expected.",
142: RasterTestUtils.imageEquals(((GridCoverage2D) rsp
143: .recolorCoverage(gc)).geophysics(true)
144: .getRenderedImage(), "fourBandRecolored.png"));
145:
146: }
147: }
|