Hi, i have a problem that i dont understand if GEOTOOLS handles (maybe with
some HINTS), basically i read a TIFF image then i serialized it :










*public static byte[] gridToBytes(GridCoverage2D grid) throws IOException
{ ByteArrayOutputStream baos = new ByteArrayOutputStream(); GeoTiffWriter
writer = new GeoTiffWriter(baos, null); writer.write(grid,
null); writer.dispose(); byte[] bytes =
baos.toByteArray(); baos.flush(); baos.close(); return bytes;}*

Then i deserialize it with:













*    public static GridCoverage2D bytesToGrid(byte[] bytes) throws
IOException {        ByteArrayInputStream bais = new
ByteArrayInputStream(bytes);        GeoTiffReader reader = null;        try
{            Hints hints = new
Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
reader = new GeoTiffReader(bais, hints);            GridCoverage2D grid =
reader.read(null);            bais.close();            return grid;
} catch (IllegalArgumentException e) {            throw new
IOException("Error on deserialization on tile");        }    }*

It works fine with some images, but i found some tiff (i have 150 of those,
uploaded one for you if you wanna try:
https://mega.nz/file/qJlEyTIQ#jgCE5pwfD5Y_AiUj2hSLTvTIS0lZ4CSm5D0Vb0eTk7U )
that gaves this error on deserialization:








*Caused by: java.lang.IllegalArgumentException: bandOffsets.length is
wrong! at
javax.imageio.ImageTypeSpecifier$Interleaved.<init>(ImageTypeSpecifier.java:286)
at
javax.imageio.ImageTypeSpecifier.createInterleaved(ImageTypeSpecifier.java:399)
at
it.geosolutions.imageio.plugins.tiff.TIFFDecompressor.getRawImageTypeSpecifier(TIFFDecompressor.java:1027)
at
it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getImageTypes(TIFFImageReader.java:1359)
at
org.geotools.coverage.grid.io.AbstractGridCoverage2DReader.setLayout(AbstractGridCoverage2DReader.java:1167)
at org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:342)*
And, using gdal i get:

*Warning 1: TIFFReadDirectory:Sum of Photometric type-related color
channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color
channels as ExtraSamples.*
GDAL handle it putting this band (should bhe the 4th band, alpha channel)
as ExtraSamples.
How can I walk-around with GeoTools to read the image back? Are there any
HINTS that i could use?

Thanks
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to