<span class="Apple-style-span" style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">Morning all, <div><br></div><div>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. </div>
<div><br></div><div>To calculate band statistics I use the following code which returns 1000 lines of error before exiting</div><div><br></div><div><div>def get_band_stats(band):</div><div> NDV = band.GetNoDataValue()</div>
<div> bandMin = band.GetMinimum()</div><div> bandMax = band.GetMaximum()</div><div> if bandMin is None or bandMax is None:</div><div> #Approx has to be set to false to ensure that an accurate Min/Max are calculated...</div>
<div> (bandMin, bandMax) = band.ComputeRasterMinMax(False)</div><div> return NDV, bandMin, bandMax</div></div><div><br></div><div>....</div><div>ERROR 1: IReadBlock failed at X offset 20, Y offset 25</div><div>ERROR 1: IReadBlock failed at X offset 21, Y offset 25</div>
<div>....</div><div><br></div><div>This cuts off after 1000 lines.</div><div><br></div><div>Commenting out the if statement, thereby using the "fast" method for getting the min/max returns the following error:</div>
<div><br></div><div><div>error: cannot decode code stream</div><div>ERROR 1: IReadBlock failed at X offset 0, Y offset 0</div><div>ERROR 1: GetBlockRef failed at X block offset 0, Y block offset 0</div></div><div><br></div>
<div>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? </div>
<div><br></div><div>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? </div><div><br></div><div>Many thanks, </div><div>Jay</div></span>