After doing calculations on a raster and saving it, the image statistics are wrong and need updating.
I find examples saying that this should do the job, like in this example:
dsband.WriteArray(data) dsband.FlushCache() dsband.GetStatistics(0,1)
However this does not seem to update my band statistics correctly, they seem ok in Python with data.max() and data.min(), but opening the file in QuantumGis (image properties>style>load min/max) shows the wrong stats. I only get new image statistics correctly by separately opening and setting statistics like this:
driver = gdal.GetDriverByName('GTiff') driver.Register() ds = gdal.Open(infile, gdal.GA_Update) dsband = ds.GetRasterBand(1) (newmin, newmax)= dsband.ComputeRasterMinMax(0) (newmean, newstdv) = dsband.ComputeBandStats(1) dsband.SetStatistics(newmin, newmax,newmean, newstdv) dsband.FlushCache() dsband = None ds = None
So what's the difference between both and why does QGis only show the correct stats with the second code?
thanks for any advice!