Hi All,

I would like to create a GridCoverage2D from an integer array and finally
create a GeoTiff output.
However, after creating the grid coverage (which works), I keep getting
errors during the GeoTiff write process: array index out of bounds.

As I am new to this field and GeoTools, I would really appreciate your help.

My code is given here:
~~~
        //input: int[1000][1000] data
        ColorModel colorModel = new ComponentColorModel(
                ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false,
                ColorModel.TRANSLUCENT, DataBuffer.TYPE_INT);
        SampleModel model = new
        BandedSampleModel(DataBuffer.TYPE_INT, 100, 100, 1);
        DataBuffer buffer = new DataBufferInt(data, data.length);
        WritableRaster raster = Raster.createWritableRaster(model, buffer,
null);
        BufferedImage img = new BufferedImage(colorModel, raster, false,
null);
        GridCoverageFactory factory =
CoverageFactoryFinder.getGridCoverageFactory(null);
        Envelope2D envelope = new
Envelope2D(CRS.getProjectedCRS(DefaultGeographicCRS.WGS84), 0, 0, 100, 100);
        GridCoverage2D cov = factory.create("Coverage", img, envelope);

        File outputFile = new File("D:\\Output.tif");
        GeoTiffFormat format = new GeoTiffFormat();
        GeoTiffWriter writer = (GeoTiffWriter)format.getWriter(outputFile);
        writer.write(cov, null);

Console output:
~~~
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100
        at java.awt.image.DataBufferInt.getElem(DataBufferInt.java:181)
        at
java.awt.image.BandedSampleModel.getDataElements(BandedSampleModel.java:297)
        at java.awt.image.SampleModel.getDataElements(SampleModel.java:403)
        at java.awt.image.Raster.getDataElements(Raster.java:1503)
        at java.awt.image.BufferedImage.getData(BufferedImage.java:1411)
        at
javax.media.jai.RenderedImageAdapter.getData(RenderedImageAdapter.java:158)
        at
it.geosolutions.imageioimpl.plugins.tiff.TIFFImageWriter.writeTile(TIFFImageWriter.java:1792)
        at
it.geosolutions.imageioimpl.plugins.tiff.TIFFImageWriter.write(TIFFImageWriter.java:2851)
        at
it.geosolutions.imageioimpl.plugins.tiff.TIFFImageWriter.write(TIFFImageWriter.java:2582)
        at
org.geotools.gce.geotiff.GeoTiffWriter.writeImage(GeoTiffWriter.java:391)
        at
org.geotools.gce.geotiff.GeoTiffWriter.write(GeoTiffWriter.java:222)
        at geotifftest.GeoTiff.writeMap3(GeoTiff.java:158)

Not sure where the problem is, as the input matrix has dimensions 1000 x
1000.
Please let me know any suggestions to solve this problem or to use another
approach.

Many thanks,
Jan
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to