I want to read a specific GeoTIFF file, which is a BigTIFF containing a set of uncompressed 128x128 tiles of float32 data. My code snippet requests a small rectangle. It works with ordinary TIFFs, small test RGBA BigTIFFs, and a small test float32 BigTIFF. However, with the file in question, it returns an exception. If the requested rectangle is inside the first tile, the error is java.lang.ArrayIndexOutOfBoundsException with the message 'Coordinate out of bounds!'. Outside the first tile, the exception is java.awt.image.RasterFormatException (shown below). I'm using version 3.9.4 of the twelvemonkeys ImageIO code. I've also tried 3.8.1 with the same result.
Code fragment:
try {
ImageInputStream input = ImageIO.createImageInputStream(file);
ImageReader reader = ImageIO.getImageReaders(input).next();
System.out.println( "Using reader: " + reader );
reader.setInput(input);
int width = reader.getWidth(reader.getMinIndex());
int height = reader.getHeight(reader.getMinIndex());
System.out.println( "width, height: " + width + ", " + height );
ImageReadParam param = reader.getDefaultReadParam();
Rectangle rect = new Rectangle(256, 256, 2, 2);
param.setSourceRegion(rect);
System.out.println( "sourceRegion: " + param.getSourceRegion().toString() );
BufferedImage image = reader.read(0, param);
}
catch (Exception e) {
System.out.println( "Exception:" );
e.printStackTrace();
}
Output:
Using reader: com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader@76ccd017
width, height: 58000, 66500
sourceRegion: java.awt.Rectangle[x=256,y=256,width=2,height=2]
Exception:
java.awt.image.RasterFormatException: (parentX + width) is outside raster
at java.desktop/java.awt.image.Raster.createChild(Raster.java:1526)
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.clipRowToRect(TIFFImageReader.java:1909)
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1094)
at smallest_test.main(smallest_test.java:58)
The BigTIFF file is available from this page: https://www.data.gov.uk/dataset/8311f42d-bddd-4cd4-98a3-e543de5be4cb/lidar-composite-dtm-2019-10m Beware: the download is 3.6Gb; the file is 15.5Gb.
I can see three possibilities:
- My code is wrong.
- The file is broken.
- The file uses part of the Big TIFF specification which HaraldK and Twelvemonkeys haven't implemented yet.
Regarding possibility 2, I have bodged some code that can read data points from the file, which indicates that it's not completely mangled. The data (terrain height) which I extracted matches my expectations and other datasets.
As for what's actually happening, the exception print seems to be alleging that 256+2 is larger than 58000, which seems unlikely.
I'd like your thoughts about what's wrong, and why.