Skip to content
Prev 15862 / 29559 Next

wrong stats in GTiff files made with writeRaster() (through rgdal?)

I think this is a real need. The tif files currently generated by
writeRaster() cannot be easily modified
with gdal utilities, beacause gdalinfo can force the calculation of
the min/max values nut not of the
mean and sd unless they do not exist:

from http://www.gdal.org/gdalinfo.html :

DESCRIPTION

The gdalinfo program lists various information about a GDAL supported
raster dataset.

-mm
Force computation of the actual min/max values for each band in the dataset.
-stats
Read and display image statistics. Force computation if no statistics
are stored in an image.

Perhaps a solution would be to let the files with "no statistics
stored" instead of the current wrong
default values. I think this would be ok for qgis also, as I think
that qgis reads the mean and sd from
the tif file if they are available (but with qgis you never know...).
If possible, I would much prefer
correct stat info than no info (but no info is better than wrong info).

By now I have to write the files again using gdal_translate -stats,
that forces stats calculation:

writeRaster(adls204_150_93,filename="adls204_150_93",format="GTiff",dataType="INT2U",NAflag=0,overwrite=T)
GDALinfo("adls204_150_93.tif") #wrong stats:
system("gdal_translate -stats adls204_150_93.tif test.tif")
system("gdal_translate -stats test.tif adls204_150_93.tif")
GDALinfo("adls204_150_93.tif")
system("rm test.tif")

Agus

2012/8/14 Robert J. Hijmans <r.hijmans at gmail.com>: