1

I am new to geotools. I need to get a horizontal stripe of bytes from the image data without buffering the whole image. I've looked at the various envelopes and pretty sure I could use just Rectangle2D since I don't need the coordinaterefsystem. But for the life of me I can't figure out how to use the rectangle/envelope without doing:

GridCoverage2DReader gridReader = format.getReader(this.getInputFile(), hints);
GridCoverage2D gridCoverage = gridReader.read(null);

I don't see a replacement in JAI-EXT for ImageReadDescriptor.

For those wondering why, legacy code appears to have a memory leak. Below is the code where I see avail memory drop with each loop. I used Thread.sleep(x) so I could watch it in top. This is not a heap issue, the machine core dumps with an out of memory error and an exit code of 137. Java mission control shows the heap is cleaned nicely.

RenderedImage img = ImageReadDescriptor.create(ImageInputStream iis, ...);
... //calculate stripeSize

byte[] writeBuff = new byte[stripeSize*numLines];
for(nCalculatedChunksOfLines){
  Rectangle tb = new Rectangle(0, n, sample, linesInChunk );
  Raster stripe = img.getData(tb);

  ...rest of processing bypassed for debugging....
  if(stripe != null){
    continue;
  }
}

I would rather replace the legacy code but if there are no simple options then a suggested fix to the legacy code would be helpful. I'm going to test closing and opening the stream for each rectangle retrieve.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.