Reading huge files without having to load everything in memory
I am new to JAI development, and I'm working on a GIS project. My objective is to read huge files (up to 2gb or more) and process them, without having to get everything in memory, so one could use a heap space of 64mb.
I know I have to tile the image, and read the tiles as I need, but I'm having some problems with this.
I used the setSourceRegion() method to define my region of interest, and passed the corresponding ImageReadParam to the ImageReader, finally to call the readAsRenderedImage method. But the resulting RenderedImage is actually the whole image, and not only the region I defined.
Do you know how can I achieve this?
Here the code I'm using:
ImageReadParam imageReadParam = new TIFFImageReadParam();
RenderedOp resultOp = ImageReadDescriptor.create(new FileImageInputStream(new File("radar.tif")),0,true,false,true,null,null, imageReadParam,null,null);
ImageReader imageReader = (ImageReader)resultOp.getProperty("JAI.ImageReader");
imageReadParam.setSourceSubsampling(1, 1, 0, 0);
RenderedImage image = imageReader.readAsRenderedImage(0, imageReadParam);
RasterMetadata rasterMetadata = new RasterMetadata(0,0,0,0,0,0);
GridCoverageFactory.createGridCoverage(image, rasterMetadata).show(); //This is the method that shows the image, for debuging purposes only. The image shown should be only the region I defined, but loads as the whole image (consuming all my memory, if i use large files)