Details
Description
I tried to create a geotiff file with USHORT data type, but a OutOfMemoryError exception was throwed when saving the raster. I also tried other data types such as SHORT or INT. It turned out that the code works with those data types except USHORT.
JUnit tests pasted below:
----------------------------------------------------------------
import java.awt.image.DataBuffer;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.File;
import javax.media.jai.RasterFactory;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.factory.FactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.gce.geotiff.GeoTiffFormat;
import org.geotools.gce.geotiff.GeoTiffWriteParams;
import org.geotools.geometry.Envelope2D;
import org.geotools.referencing.CRS;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class AppTest extends TestCase {
public void testApp() throws Exception {
//It works when TYPE_USHORT changes to other data types, such as TYPE_SHORT, TYPE_INT, etc.
WritableRaster _raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_USHORT, 100, 50, 1, null);
for(int _row = 0;_row<50;_row++){
for(int _col=0;_col < 100;_col++)
}
Envelope2D _env = new Envelope2D(CRS.decode("EPSG:4326", true), 0, 0, 180, 90);
GridCoverage2D _grid = new GridCoverageFactory().create("test1", _raster, _env);
GeoTiffFormat _format = new GeoTiffFormat();
GeoTiffWriteParams _wp = new GeoTiffWriteParams();
_wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
_wp.setCompressionType("LZW");
_wp.setCompressionQuality(0.75F);
//Exception throws here
_format.getWriter(new File("c:
test.tif")).write(_grid, null);
}
}