001: /**
002: *
003: */package org.geotools.gce.gtopo30;
004:
005: import java.awt.Rectangle;
006: import java.net.URL;
007:
008: import javax.media.jai.JAI;
009: import javax.media.jai.RecyclingTileFactory;
010: import javax.media.jai.TileCache;
011:
012: import org.geotools.coverage.grid.GeneralGridRange;
013: import org.geotools.coverage.grid.GridCoverage2D;
014: import org.geotools.coverage.grid.GridGeometry2D;
015: import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
016: import org.geotools.coverage.grid.io.AbstractGridFormat;
017: import org.geotools.resources.TestData;
018: import org.geotools.resources.image.CoverageUtilities;
019: import org.opengis.parameter.GeneralParameterValue;
020: import org.opengis.parameter.ParameterValueGroup;
021:
022: /**
023: * Purpose of this class is testing the ability of this plug in to read and
024: * write back the in gtopo30 format.
025: *
026: * @author Simone Giannecchini
027: * @source $URL:
028: * http://svn.geotools.org/geotools/trunk/gt/plugin/gtopo30/test/org/geotools/gce/gtopo30/GT30ReaderWriterTest.java $
029: */
030: public class GT30DecimationTest extends GT30TestBase {
031: /**
032: * Constructor for GT30ReaderTest.
033: *
034: * @param arg0
035: */
036: public GT30DecimationTest(String arg0) {
037: super (arg0);
038: }
039:
040: /**
041: * Testing reader and writer for gtopo. This test first of all read an
042: * existing gtopo tessel into a coverage object, therefore it writes it back
043: * onto the disk. Once the coverage is written back\ it loads it again
044: * building a new coverage which is finally visualized.
045: *
046: * @throws Exception
047: */
048: public void test() throws Exception {
049:
050: URL statURL = TestData.url(this , (new StringBuffer(
051: this .fileName).append(".DEM").toString()));
052: AbstractGridFormat format = (AbstractGridFormat) new GTopo30FormatFactory()
053: .createFormat();
054:
055: // using a big tile cache
056: final JAI jaiDef = JAI.getDefaultInstance();
057: final TileCache cache = jaiDef.getTileCache();
058: cache.setMemoryCapacity(64 * 1024 * 1024);
059: cache.setMemoryThreshold(1.0f);
060: // final TCTool tool= new TCTool();
061:
062: // setting JAI wide hints
063: jaiDef.setRenderingHint(JAI.KEY_CACHED_TILE_RECYCLING_ENABLED,
064: Boolean.TRUE);
065:
066: // tile factory and recycler
067: final RecyclingTileFactory recyclingFactory = new RecyclingTileFactory();
068: jaiDef.setRenderingHint(JAI.KEY_TILE_FACTORY, recyclingFactory);
069: jaiDef
070: .setRenderingHint(JAI.KEY_TILE_RECYCLER,
071: recyclingFactory);
072:
073: if (format.accepts(statURL)) {
074:
075: /**
076: *
077: * STEP 1 Reading the coverage into memory in order to write it down
078: * again
079: *
080: */
081: // get a reader
082: AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) format
083: .getReader(statURL);
084:
085: // get a grid coverage
086: final ParameterValueGroup params = reader.getFormat()
087: .getReadParameters();
088: params.parameter(
089: AbstractGridFormat.READ_GRIDGEOMETRY2D.getName()
090: .toString()).setValue(
091: new GridGeometry2D(new GeneralGridRange(
092: new Rectangle(0, 0, 640, 480)), reader
093: .getOriginalEnvelope()));
094: gc = ((GridCoverage2D) reader
095: .read((GeneralParameterValue[]) params.values()
096: .toArray(new GeneralParameterValue[1])));
097: assertTrue(CoverageUtilities.hasRenderingCategories(gc));
098: if (TestData.isInteractiveTest()) {
099: // logging some info
100: logger
101: .info(gc.getCoordinateReferenceSystem2D()
102: .toWKT());
103: logger.info(gc.toString());
104: gc.show();
105: } else {
106: gc.getRenderedImage().getData();
107: }
108:
109: }
110: }
111:
112: public static final void main(String[] args) throws Exception {
113: junit.textui.TestRunner.run(GT30DecimationTest.class);
114: }
115:
116: }
|