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.io.File;
021: import java.io.InputStream;
022: import java.net.URL;
023: import java.util.Map;
024: import java.util.Properties;
025: import java.util.logging.Level;
026: import java.util.logging.Logger;
027:
028: import javax.imageio.ImageIO;
029:
030: import junit.framework.TestCase;
031:
032: import org.geotools.arcsde.ArcSDERasterFormatFactory;
033: import org.geotools.arcsde.pool.ArcSDEConnectionConfig;
034: import org.geotools.arcsde.pool.ArcSDEConnectionPool;
035: import org.geotools.coverage.grid.GeneralGridRange;
036: import org.geotools.coverage.grid.GridCoverage2D;
037: import org.geotools.coverage.grid.GridGeometry2D;
038: import org.geotools.data.DataSourceException;
039: import org.geotools.data.coverage.grid.AbstractGridCoverage2DReader;
040: import org.geotools.data.coverage.grid.AbstractGridFormat;
041: import org.geotools.geometry.jts.ReferencedEnvelope;
042: import org.geotools.parameter.Parameter;
043: import org.geotools.referencing.CRS;
044: import org.opengis.coverage.grid.Format;
045: import org.opengis.coverage.grid.GridCoverageReader;
046: import org.opengis.parameter.GeneralParameterValue;
047: import org.opengis.referencing.crs.CoordinateReferenceSystem;
048:
049: /**
050: * Tests the functionality of the ArcSDE raster-display package to read rasters from an
051: * ArcSDE database
052: *
053: * @author Saul Farber, (based on ArcSDEPoolTest by Gabriel Roldan)
054: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/gce/ArcSDEGCReaderWorkingTest.java $
055: * @version $Id: ArcSDEGCReaderWorkingTest.java 27526 2007-10-17 19:20:03Z saul.farber $
056: */
057: public class ArcSDEGCReaderWorkingTest extends TestCase {
058:
059: private CoordinateReferenceSystem crs;
060: private GridGeometry2D statewideRealWorldExampleRes,
061: southShoreExampleRes;
062:
063: private Properties conProps;
064:
065: /**
066: * Creates a new ArcSDEConnectionPoolTest object.
067: *
068: */
069: public ArcSDEGCReaderWorkingTest(String name) throws Exception {
070: super (name);
071:
072: conProps = new Properties();
073: String propsFile = "raster-testparams.properties";
074: URL conParamsSource = org.geotools.test.TestData.url(
075: new ArcSDEPyramidTest(""), propsFile);
076:
077: InputStream in = conParamsSource.openStream();
078: if (in == null) {
079: throw new IllegalStateException("cannot find test params: "
080: + conParamsSource.toExternalForm());
081: }
082: conProps.load(in);
083: in.close();
084: }
085:
086: public void setUp() throws Exception {
087: super .setUp();
088:
089: crs = CRS.decode("EPSG:26986");
090: // 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]
091: statewideRealWorldExampleRes = new GridGeometry2D(
092: new GeneralGridRange(new Rectangle(500, 285)),
093: new ReferencedEnvelope(33000.25, 332999.75, 782500.143,
094: 953499.857, crs));
095:
096: // x=0,y=0,width=500,height=285] envelope -- [222,175.135 m 800,289.513 m , 294,775.014 m 841,671.444 m]
097: southShoreExampleRes = new GridGeometry2D(new GeneralGridRange(
098: new Rectangle(500, 285)), new ReferencedEnvelope(
099: 222175.135, 294775.014, 800289.513, 841671.444, crs));
100:
101: }
102:
103: public void testWorkingExample() throws Exception {
104:
105: String fourbandurl = conProps.getProperty("fourbandurl");
106:
107: GridCoverage2D gc;
108: Format f = new ArcSDERasterFormatFactory().createFormat();
109: AbstractGridCoverage2DReader r = (AbstractGridCoverage2DReader) ((AbstractGridFormat) f)
110: .getReader(fourbandurl);
111:
112: GeneralParameterValue[] requestParams = new Parameter[1];
113:
114: //requestParams[0] = new Parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D,statewideRealWorldExampleRes);
115: requestParams[0] = new Parameter(
116: AbstractGridFormat.READ_GRIDGEOMETRY2D,
117: southShoreExampleRes);
118: gc = (GridCoverage2D) r.read(requestParams);
119: assertNotNull(gc);
120: try {
121: ImageIO.write(gc.geophysics(true).getRenderedImage(),
122: "PNG", new File("workingTestOutput1.png"));
123: } catch (Exception e) {
124: e.printStackTrace();
125: }
126: }
127: }
|