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.io.File;
022: import java.io.InputStream;
023: import java.net.URL;
024: import java.util.Map;
025: import java.util.Properties;
026: import java.util.logging.Level;
027: import java.util.logging.Logger;
028:
029: import javax.imageio.ImageIO;
030:
031: import junit.framework.TestCase;
032:
033: import org.geotools.arcsde.ArcSDERasterFormatFactory;
034: import org.geotools.arcsde.pool.ArcSDEConnectionConfig;
035: import org.geotools.arcsde.pool.ArcSDEConnectionPool;
036: import org.geotools.coverage.grid.GeneralGridRange;
037: import org.geotools.coverage.grid.GridCoverage2D;
038: import org.geotools.coverage.grid.GridGeometry2D;
039: import org.geotools.data.DataSourceException;
040: import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
041: import org.geotools.coverage.grid.io.AbstractGridFormat;
042: import org.geotools.geometry.jts.ReferencedEnvelope;
043: import org.geotools.parameter.Parameter;
044: import org.geotools.referencing.CRS;
045: import org.opengis.coverage.grid.Format;
046: import org.opengis.coverage.grid.GridCoverageReader;
047: import org.opengis.parameter.GeneralParameterValue;
048: import org.opengis.referencing.crs.CoordinateReferenceSystem;
049:
050: /**
051: * Tests the functionality of the ArcSDE raster-display package to read rasters from an
052: * ArcSDE database
053: *
054: * @author Saul Farber, (based on ArcSDEPoolTest by Gabriel Roldan)
055: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/gce/ArcSDEGCReaderSpatialTest.java $
056: * @version $Id: ArcSDEGCReaderSpatialTest.java 25075 2007-04-09 19:20:46Z desruisseaux $
057: */
058: public class ArcSDEGCReaderSpatialTest extends TestCase {
059:
060: private CoordinateReferenceSystem crs;
061: private GridGeometry2D highRes;
062: private GridGeometry2D medRes;
063: private GridGeometry2D lowRes;
064: private GridGeometry2D realWordlExampleRes;
065: private GridGeometry2D statewideRealWorldExampleRes;
066: private Properties conProps;
067:
068: /**
069: * Creates a new ArcSDEConnectionPoolTest object.
070: *
071: */
072: public ArcSDEGCReaderSpatialTest(String name) throws Exception {
073: super (name);
074: }
075:
076: public void setUp() throws Exception {
077: super .setUp();
078:
079: //one-time setup
080: if (conProps != null)
081: return;
082:
083: conProps = new Properties();
084: String propsFile = "raster-testparams.properties";
085: InputStream in = org.geotools.test.TestData.openStream(null,
086: propsFile);
087: conProps.load(in);
088: in.close();
089:
090: crs = CRS.decode("EPSG:26986");
091: highRes = new GridGeometry2D(new GeneralGridRange(
092: new Rectangle(1000, 1000)), new ReferencedEnvelope(
093: 150000.0, 151000.0, 900000.0, 901000.0, crs));
094: medRes = new GridGeometry2D(new GeneralGridRange(new Rectangle(
095: 500, 500)), new ReferencedEnvelope(150000.0, 151000.0,
096: 900000.0, 901000.0, crs));
097: lowRes = new GridGeometry2D(new GeneralGridRange(new Rectangle(
098: 200, 200)), new ReferencedEnvelope(30000.0, 300000.0,
099: 630000.0, 900000.0, crs));
100: realWordlExampleRes = new GridGeometry2D(new GeneralGridRange(
101: new Rectangle(256, 128)), new ReferencedEnvelope(
102: 33000.25, 330000.225, 774000.25, 983400.225, crs));
103: // 33,000.25 m 782,500.143 m , 332,999.75 m 953,499.857 m], java.awt.Rectangle[x=0,y=0,width=500,height=285]
104: statewideRealWorldExampleRes = new GridGeometry2D(
105: new GeneralGridRange(new Rectangle(500, 285)),
106: new ReferencedEnvelope(33000.25, 332999.75, 782500.143,
107: 953499.857, crs));
108:
109: }
110:
111: public void testGetArcSDERasterFormat() throws Exception {
112:
113: Format f = new ArcSDERasterFormatFactory().createFormat();
114: assertNotNull(f);
115:
116: }
117:
118: public void testGetArcSDEGC2DReader() throws Exception {
119:
120: final String sdeUrl1 = conProps.getProperty("testrasterurl1");
121: final String sdeUrl2 = conProps.getProperty("testrasterurl2");
122: final String sdeUrl3 = conProps.getProperty("testrasterurl3");
123: final String sdeUrl4 = conProps.getProperty("testrasterurl4");
124:
125: Format f = new ArcSDERasterFormatFactory().createFormat();
126:
127: File hack = new File(sdeUrl1);
128: assertTrue(((AbstractGridFormat) f).accepts(hack));
129: AbstractGridCoverage2DReader r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
130: .getReader(hack);
131: assertNotNull(r);
132: assertNotNull(r.getOriginalEnvelope());
133: assertNotNull(r.getOriginalGridRange());
134:
135: assertTrue(((AbstractGridFormat) f).accepts(sdeUrl2));
136: r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
137: .getReader(sdeUrl2);
138: assertNotNull(r);
139: assertNotNull(r.getOriginalEnvelope());
140: assertNotNull(r.getOriginalGridRange());
141:
142: assertTrue(((AbstractGridFormat) f).accepts(sdeUrl3));
143: r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
144: .getReader(sdeUrl3);
145: assertNotNull(r);
146: assertNotNull(r.getOriginalEnvelope());
147: assertNotNull(r.getOriginalGridRange());
148:
149: assertTrue(((AbstractGridFormat) f).accepts(sdeUrl4));
150: r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
151: .getReader(sdeUrl4);
152: assertNotNull(r);
153: assertNotNull(r.getOriginalEnvelope());
154: assertNotNull(r.getOriginalGridRange());
155:
156: }
157:
158: public void testRead3BandCoverage() throws Exception {
159:
160: String threebandurl = conProps
161: .getProperty("threebandrasterurl");
162:
163: GridCoverage2D gc;
164: Format f = new ArcSDERasterFormatFactory().createFormat();
165: AbstractGridCoverage2DReader r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
166: .getReader(threebandurl);
167:
168: GeneralParameterValue[] requestParams = new Parameter[1];
169:
170: requestParams[0] = new Parameter(
171: AbstractGridFormat.READ_GRIDGEOMETRY2D, highRes);
172: gc = (GridCoverage2D) r.read(requestParams);
173: assertNotNull(gc);
174: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("threebandOutput1.png"));
175: assertTrue("Image from SDE isn't what we expected.",
176: RasterTestUtils.imageEquals(gc.geophysics(true)
177: .getRenderedImage(), "threeBandOutput1.png"));
178:
179: requestParams[0] = new Parameter(
180: AbstractGridFormat.READ_GRIDGEOMETRY2D, medRes);
181: gc = (GridCoverage2D) r.read(requestParams);
182: assertNotNull(gc);
183: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("threeBandOutput2.png"));
184: assertTrue("Image from SDE isn't what we expected.",
185: RasterTestUtils.imageEquals(gc.geophysics(true)
186: .getRenderedImage(), "threeBandOutput2.png"));
187:
188: requestParams[0] = new Parameter(
189: AbstractGridFormat.READ_GRIDGEOMETRY2D, lowRes);
190: gc = (GridCoverage2D) r.read(requestParams);
191: assertNotNull(gc);
192: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("threeBandOutput3.png"));
193: assertTrue("Image from SDE isn't what we expected.",
194: RasterTestUtils.imageEquals(gc.geophysics(true)
195: .getRenderedImage(), "threeBandOutput3.png"));
196:
197: requestParams[0] = new Parameter(
198: AbstractGridFormat.READ_GRIDGEOMETRY2D,
199: realWordlExampleRes);
200: gc = (GridCoverage2D) r.read(requestParams);
201: assertNotNull(gc);
202: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("threeBandOutput4.png"));
203: assertTrue("Image from SDE isn't what we expected.",
204: RasterTestUtils.imageEquals(gc.geophysics(true)
205: .getRenderedImage(), "threeBandOutput4.png"));
206: }
207:
208: public void testRead4BandCoverage() throws Exception {
209:
210: String fourbandurl = conProps.getProperty("fourbandrasterurl");
211:
212: GridCoverage2D gc;
213: Format f = new ArcSDERasterFormatFactory().createFormat();
214: AbstractGridCoverage2DReader r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
215: .getReader(fourbandurl);
216:
217: GeneralParameterValue[] requestParams = new Parameter[1];
218:
219: requestParams[0] = new Parameter(
220: AbstractGridFormat.READ_GRIDGEOMETRY2D, highRes);
221: gc = (GridCoverage2D) r.read(requestParams);
222: assertNotNull(gc);
223: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("fourbandOutput1.png"));
224: assertTrue("Image from SDE isn't what we expected.",
225: RasterTestUtils.imageEquals(gc.geophysics(true)
226: .getRenderedImage(), "fourbandOutput1.png"));
227:
228: requestParams[0] = new Parameter(
229: AbstractGridFormat.READ_GRIDGEOMETRY2D, medRes);
230: gc = (GridCoverage2D) r.read(requestParams);
231: assertNotNull(gc);
232: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("fourbandOutput2.png"));
233: assertTrue("Image from SDE isn't what we expected.",
234: RasterTestUtils.imageEquals(gc.geophysics(true)
235: .getRenderedImage(), "fourbandOutput2.png"));
236:
237: requestParams[0] = new Parameter(
238: AbstractGridFormat.READ_GRIDGEOMETRY2D, lowRes);
239: gc = (GridCoverage2D) r.read(requestParams);
240: assertNotNull(gc);
241: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("fourbandOutput3.png"));
242: assertTrue("Image from SDE isn't what we expected.",
243: RasterTestUtils.imageEquals(gc.geophysics(true)
244: .getRenderedImage(), "fourbandOutput3.png"));
245:
246: requestParams[0] = new Parameter(
247: AbstractGridFormat.READ_GRIDGEOMETRY2D,
248: realWordlExampleRes);
249: gc = (GridCoverage2D) r.read(requestParams);
250: assertNotNull(gc);
251: //ImageIO.write(gc.geophysics(true).getRenderedImage(), "PNG", new File("fourbandOutput4.png"));
252: assertTrue("Image from SDE isn't what we expected.",
253: RasterTestUtils.imageEquals(gc.geophysics(true)
254: .getRenderedImage(), "fourbandOutput4.png"));
255: }
256: }
|