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.Dimension;
020: import java.awt.Rectangle;
021: import java.io.File;
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.net.URL;
025: import java.util.HashMap;
026: import java.util.Iterator;
027: import java.util.Map;
028: import java.util.Properties;
029: import java.util.Vector;
030: import java.util.logging.Logger;
031:
032: import junit.framework.TestCase;
033:
034: import org.geotools.arcsde.data.ArcSDEQueryTest;
035: import org.geotools.arcsde.gce.ArcSDEPyramid;
036: import org.geotools.arcsde.gce.RasterQueryInfo;
037: import org.geotools.arcsde.pool.ArcSDEConnectionConfig;
038: import org.geotools.arcsde.pool.ArcSDEConnectionPool;
039: import org.geotools.arcsde.pool.ArcSDEConnectionPoolFactory;
040: import org.geotools.arcsde.pool.ArcSDEPooledConnection;
041: import org.geotools.arcsde.pool.UnavailableArcSDEConnectionException;
042: import org.geotools.coverage.grid.GeneralGridRange;
043: import org.geotools.coverage.grid.GridGeometry2D;
044: import org.geotools.data.DataSourceException;
045: import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
046: import org.geotools.coverage.grid.io.AbstractGridFormat;
047: import org.geotools.geometry.jts.ReferencedEnvelope;
048: import org.geotools.parameter.Parameter;
049: import org.geotools.referencing.CRS;
050: import org.opengis.coverage.grid.Format;
051: import org.opengis.coverage.grid.GridCoverage;
052: import org.opengis.coverage.grid.GridCoverageReader;
053: import org.opengis.coverage.grid.GridRange;
054: import org.opengis.parameter.GeneralParameterValue;
055: import org.opengis.referencing.crs.CoordinateReferenceSystem;
056: import org.opengis.geometry.BoundingBox;
057:
058: import com.esri.sde.sdk.client.SDEPoint;
059: import com.esri.sde.sdk.client.SeConnection;
060: import com.esri.sde.sdk.client.SeException;
061: import com.esri.sde.sdk.client.SeExtent;
062: import com.esri.sde.sdk.client.SeFilter;
063: import com.esri.sde.sdk.client.SeLayer;
064: import com.esri.sde.sdk.client.SeQuery;
065: import com.esri.sde.sdk.client.SeRaster;
066: import com.esri.sde.sdk.client.SeRasterAttr;
067: import com.esri.sde.sdk.client.SeRasterBand;
068: import com.esri.sde.sdk.client.SeRasterColumn;
069: import com.esri.sde.sdk.client.SeRasterConstraint;
070: import com.esri.sde.sdk.client.SeRasterTile;
071: import com.esri.sde.sdk.client.SeRow;
072: import com.esri.sde.sdk.client.SeShape;
073: import com.esri.sde.sdk.client.SeShapeFilter;
074: import com.esri.sde.sdk.client.SeSqlConstruct;
075: import com.esri.sde.sdk.client.SeTable;
076:
077: /**
078: * Tests the functionality of the ArcSDE raster-display package to read rasters
079: * from an ArcSDE database
080: *
081: * @author Saul Farber, (based on ArcSDEPoolTest by Gabriel Roldan)
082: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/gce/ArcSDEPyramidTest.java $
083: * @version $Id: ArcSDEPyramidTest.java 27863 2007-11-12 20:34:34Z desruisseaux $
084: */
085: public class ArcSDEPyramidTest extends TestCase {
086:
087: private static Logger LOGGER = org.geotools.util.logging.Logging
088: .getLogger("org.geotools.arcsde.gce");
089: private ArcSDEConnectionPool pool;
090: private Properties conProps;
091:
092: public ArcSDEPyramidTest(String name) {
093: super (name);
094: }
095:
096: protected void setUp() throws Exception {
097: super .setUp();
098: conProps = new Properties();
099: InputStream in = org.geotools.test.TestData.url(null,
100: "raster-testparams.properties").openStream();
101: conProps.load(in);
102: in.close();
103: pool = ArcSDEConnectionPoolFactory.getInstance().createPool(
104: new ArcSDEConnectionConfig(conProps));
105:
106: }
107:
108: public void testArcSDEPyramidHypothetical() throws Exception {
109:
110: ArcSDEPyramid pyramid = new ArcSDEPyramid(10, 10, 2);
111: pyramid.addPyramidLevel(0, new SeExtent(0, 0, 100, 100), null,
112: null, 10, 10, new Dimension(100, 100));
113: pyramid.addPyramidLevel(1, new SeExtent(0, 0, 100, 100), null,
114: null, 5, 5, new Dimension(50, 50));
115:
116: RasterQueryInfo ret = pyramid.fitExtentToRasterPixelGrid(
117: new ReferencedEnvelope(0, 10, 0, 10, null), 0);
118: assertTrue(ret.envelope.equals(new ReferencedEnvelope(0, 10, 0,
119: 10, null)));
120: assertTrue(ret.image.width == 10 && ret.image.height == 10);
121:
122: ret = pyramid.fitExtentToRasterPixelGrid(
123: new ReferencedEnvelope(0, 9, 0, 9, null), 0);
124: assertTrue(ret.envelope
125: .intersects((BoundingBox) new ReferencedEnvelope(0, 9,
126: 0, 9, null)));
127: assertTrue(ret.image.width == 9 && ret.image.height == 9);
128:
129: ret = pyramid.fitExtentToRasterPixelGrid(
130: new ReferencedEnvelope(15, 300, 15, 300, null), 1);
131: assertTrue(ret.envelope.equals(new ReferencedEnvelope(14, 300,
132: 14, 300, null)));
133: assertTrue(ret.image.width == 143 && ret.image.height == 143);
134:
135: ret = pyramid.fitExtentToRasterPixelGrid(
136: new ReferencedEnvelope(-100, 200, -100, 200, null), 1);
137: assertTrue(ret.envelope.equals(new ReferencedEnvelope(-100,
138: 200, -100, 200, null)));
139: assertTrue(ret.image.width == 150 && ret.image.height == 150);
140: }
141:
142: public void testArcSDEPyramidThreeBand() throws Exception {
143:
144: ArcSDEPooledConnection scon = pool.getConnection();
145: SeRasterAttr rAttr;
146: try {
147: SeQuery q = new SeQuery(scon, new String[] { "RASTER" },
148: new SeSqlConstruct(conProps
149: .getProperty("threebandtable")));
150: q.prepareQuery();
151: q.execute();
152: SeRow r = q.fetch();
153: rAttr = r.getRaster(0);
154: } catch (SeException se) {
155: scon.close();
156: throw new RuntimeException(se.getSeError().getErrDesc(), se);
157: }
158:
159: CoordinateReferenceSystem crs = CRS.decode(conProps
160: .getProperty("tableCRS"));
161: ArcSDEPyramid pyramid = new ArcSDEPyramid(rAttr, crs);
162: scon.close();
163:
164: assertTrue(pyramid.getPyramidLevel(0).getYOffset() != 0);
165:
166: ReferencedEnvelope env = new ReferencedEnvelope(33000.25,
167: 48000.225, 774000.25, 783400.225, crs);
168: Rectangle imageSize = new Rectangle(256, 128);
169: int imgLevel = pyramid.pickOptimalRasterLevel(env, imageSize);
170: RasterQueryInfo ret = pyramid.fitExtentToRasterPixelGrid(env,
171: imgLevel);
172: assertTrue(imgLevel == 6);
173: //LOGGER.info(ret.image + "");
174: //LOGGER.info(ret.envelope + "");
175: assertTrue(ret.image.equals(new Rectangle(-1, 5581, 470, 295)));
176: assertTrue(ret.envelope.contains((BoundingBox) env));
177:
178: env = new ReferencedEnvelope(40000.0, 41001.0, 800000.0,
179: 801001.0, crs);
180: imageSize = new Rectangle(1000, 1000);
181: imgLevel = pyramid.pickOptimalRasterLevel(env, imageSize);
182: ret = pyramid.fitExtentToRasterPixelGrid(env, imgLevel);
183: assertTrue(imgLevel == 1);
184: //LOGGER.info(ret.image + "");
185: //LOGGER.info(ret.envelope + "");
186: assertTrue(ret.image.equals(new Rectangle(6999, 160999, 1002,
187: 1002)));
188: assertTrue(ret.envelope.contains((BoundingBox) env));
189:
190: }
191:
192: public void testArcSDEPyramidFourBand() throws Exception {
193:
194: ArcSDEPooledConnection scon = pool.getConnection();
195: SeRasterAttr rAttr;
196: try {
197: SeQuery q = new SeQuery(scon, new String[] { "RASTER" },
198: new SeSqlConstruct(conProps
199: .getProperty("fourbandtable")));
200: q.prepareQuery();
201: q.execute();
202: SeRow r = q.fetch();
203: rAttr = r.getRaster(0);
204: } catch (SeException se) {
205: scon.close();
206: throw new RuntimeException(se.getSeError().getErrDesc(), se);
207: }
208:
209: CoordinateReferenceSystem crs = CRS.decode(conProps
210: .getProperty("tableCRS"));
211: ArcSDEPyramid pyramid = new ArcSDEPyramid(rAttr, crs);
212: scon.close();
213:
214: assertTrue(pyramid.getPyramidLevel(0).getYOffset() != 0);
215:
216: ReferencedEnvelope env = new ReferencedEnvelope(33000.25,
217: 48000.225, 774000.25, 783400.225, crs);
218: Rectangle imageSize = new Rectangle(256, 128);
219: int imgLevel = pyramid.pickOptimalRasterLevel(env, imageSize);
220: RasterQueryInfo ret = pyramid.fitExtentToRasterPixelGrid(env,
221: imgLevel);
222: assertTrue(imgLevel == 6);
223: //LOGGER.info(ret.image + "");
224: //LOGGER.info(ret.envelope + "");
225: assertTrue(ret.image.equals(new Rectangle(-1, 5581, 470, 295)));
226: assertTrue(ret.envelope.contains((BoundingBox) env));
227:
228: env = new ReferencedEnvelope(40000.0, 41001.0, 800000.0,
229: 801001.0, crs);
230: imageSize = new Rectangle(1000, 1000);
231: imgLevel = pyramid.pickOptimalRasterLevel(env, imageSize);
232: ret = pyramid.fitExtentToRasterPixelGrid(env, imgLevel);
233: assertTrue(imgLevel == 1);
234: //LOGGER.info(ret.image + "");
235: //LOGGER.info(ret.envelope + "");
236: assertTrue(ret.image.equals(new Rectangle(6999, 160999, 1002,
237: 1002)));
238: assertTrue(ret.envelope.contains((BoundingBox) env));
239:
240: }
241:
242: }
|