[gdal-dev] JP2k, ReadError, Python

Jay L. jzl5325 at psu.edu
Sat Jul 30 11:37:48 EDT 2011


Morning all,

I have a rather large JP2 file (created using the Kakadu driver I believe)
that I am trying to process with a python script.  I am able to open the
dataset and grab the first band.

To calculate band statistics I use the following code which returns 1000
lines of error before exiting

def get_band_stats(band):
    NDV = band.GetNoDataValue()
    bandMin = band.GetMinimum()
    bandMax = band.GetMaximum()
    if bandMin is None or bandMax is None:
        #Approx has to be set to false to ensure that an accurate Min/Max
are calculated...
        (bandMin, bandMax) = band.ComputeRasterMinMax(False)
    return NDV, bandMin, bandMax

....
ERROR 1: IReadBlock failed at X offset 20, Y offset 25
ERROR 1: IReadBlock failed at X offset 21, Y offset 25
....

This cuts off after 1000 lines.

Commenting out the if statement, thereby using the "fast" method for getting
the min/max returns the following error:

error: cannot decode code stream
ERROR 1: IReadBlock failed at X offset 0, Y offset 0
ERROR 1: GetBlockRef failed at X block offset 0, Y block offset 0

Finally, using gdalinfo I see that the image is being opened with the
ECWJP2000 driver.  I am also able to calculate statistics without a problem
and the returned values are within the expected range.  I am also able to
use gdal_translate to convert these to .tif prior to processing, but I would
rather avoid this method.  Do I need to alter my code to work with JP2 as
they are compressed?

Can I implicitly define the driver to be used with JP2 within my python code
without performing the unload all / load what I want method?

Many thanks,
Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110730/496ebddd/attachment.html


More information about the gdal-dev mailing list