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.image.BufferedImage;
020: import java.io.InputStream;
021: import java.util.Properties;
022: import java.util.logging.Level;
023: import java.util.logging.Logger;
024:
025: import junit.framework.TestCase;
026:
027: import org.geotools.arcsde.gce.band.ArcSDERasterBandCopier;
028: import org.geotools.arcsde.pool.ArcSDEConnectionConfig;
029: import org.geotools.arcsde.pool.ArcSDEConnectionPool;
030: import org.geotools.arcsde.pool.ArcSDEConnectionPoolFactory;
031: import org.geotools.arcsde.pool.ArcSDEPooledConnection;
032:
033: import com.esri.sde.sdk.client.SeException;
034: import com.esri.sde.sdk.client.SeQuery;
035: import com.esri.sde.sdk.client.SeRaster;
036: import com.esri.sde.sdk.client.SeRasterAttr;
037: import com.esri.sde.sdk.client.SeRasterConstraint;
038: import com.esri.sde.sdk.client.SeRasterTile;
039: import com.esri.sde.sdk.client.SeRow;
040: import com.esri.sde.sdk.client.SeSqlConstruct;
041:
042: /**
043: * Tests the functionality of the ArcSDE raster-display package to read rasters
044: * from an ArcSDE database.
045: *
046: * This class in particular tests the class which reads data from the underlying
047: * raster tile and copies it to a java.awt.Raster for display.
048: *
049: * @author Saul Farber
050: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/arcsde/datastore/src/test/java/org/geotools/arcsde/gce/UnsignedByteBandCopierTest.java $
051: * @version $Id: UnsignedByteBandCopierTest.java 27863 2007-11-12 20:34:34Z desruisseaux $
052: */
053: public class UnsignedByteBandCopierTest extends TestCase {
054:
055: private static Logger LOGGER = org.geotools.util.logging.Logging
056: .getLogger("org.geotools.arcsde.gce");
057: private ArcSDEConnectionPool pool;
058: private Properties conProps;
059:
060: public UnsignedByteBandCopierTest(String name) {
061: super (name);
062: }
063:
064: protected void setUp() throws Exception {
065: super .setUp();
066:
067: conProps = new Properties();
068: InputStream in = org.geotools.test.TestData.url(null,
069: "raster-testparams.properties").openStream();
070: conProps.load(in);
071: in.close();
072: pool = ArcSDEConnectionPoolFactory.getInstance().createPool(
073: new ArcSDEConnectionConfig(conProps));
074: }
075:
076: public void testLiveRasterTile() throws Exception {
077: ArcSDEPooledConnection scon = null;
078: try {
079:
080: scon = pool.getConnection();
081: SeQuery q = new SeQuery(scon, new String[] { "RASTER" },
082: new SeSqlConstruct(conProps
083: .getProperty("fourbandtable")));
084: q.prepareQuery();
085: q.execute();
086: SeRow r = q.fetch();
087: SeRasterAttr rAttr = r.getRaster(0);
088:
089: int[] bands = new int[] { 1, 2, 3 };
090: SeRasterConstraint rConstraint = new SeRasterConstraint();
091: rConstraint.setBands(bands);
092: rConstraint.setLevel(10);
093: //pick #bands random tiles in the middle of the state
094: rConstraint.setEnvelope(1, 1, 1, 1);
095: rConstraint
096: .setInterleave(SeRaster.SE_RASTER_INTERLEAVE_BSQ);
097:
098: q.queryRasterTile(rConstraint);
099:
100: BufferedImage outputImage = new BufferedImage(128, 128,
101: BufferedImage.TYPE_3BYTE_BGR);
102: ArcSDERasterBandCopier bandCopier = ArcSDERasterBandCopier
103: .getInstance(rAttr.getPixelType(), rAttr
104: .getTileWidth(), rAttr.getTileHeight());
105:
106: SeRasterTile rTile = r.getRasterTile();
107: for (int i = 0; i < bands.length; i++) {
108: LOGGER.info("copying band "
109: + rTile.getBandId().longValue());
110: bandCopier.copyPixelData(rTile,
111: outputImage.getRaster(), 0, 0, bands.length - i
112: - 1);
113: rTile = r.getRasterTile();
114: }
115:
116: //ImageIO.write(outputImage, "PNG", new File("ubbCopierTest1.png"));
117:
118: //Well, now we have an image tile. Does it have what we expect on it?
119: assertTrue(
120: "Image from SDE isn't what we expected.",
121: RasterTestUtils
122: .imageEquals(
123: outputImage,
124: conProps
125: .getProperty("unsignedbytebandcopiertest.image")));
126:
127: } catch (SeException se) {
128: LOGGER.log(Level.SEVERE, se.getSeError().getErrDesc(), se);
129: } finally {
130: if (scon != null)
131: scon.close();
132: }
133: }
134: }
|