[R-sig-Geo] wrong stats in GTiff files made with writeRaster() (through rgdal?)

Agustin Lobo alobolistas at gmail.com
Mon Aug 27 14:02:49 CEST 2012


Robert,

On Mon, Aug 20, 2012 at 7:21 AM, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
> Agus,
>
> As Roger suspected, this is a design choice; although possible, it is a
> costly to compute the mean and sd when writing in chunks (the sd in
> particular, as you need to have the mean to compute the sd) and most file
> formats cannot store this anyway, and I was not aware of any application
> using this.

I understand "this is a design choice", but I think it is a wrong one.
Having mean and sd
equal to 0 (or NaN) is not the same as having unknown mean and sd. The
point is that
gdal (not only QGIS) calculate the stats if this information is not
provided. If this info is set to 0,
gdal and QGIS cannot know that it has to be recalculated.

> I have changed raster's behavior (on R-Forge now) such that sd (denominator
> is n-1) and mean are set to their correct values for Raster objects that
> have the cell values in memory before writing the file, and to NaN (at
> least that is what GDALinfo reports), instead of zero, for other cases
> (when writing in chunks from another file). Does that help? That is, is the
> NaN understood by QGIS?
The correct values do help a lot, actually solve my problem.
Have not been able to test for the case with NaN, but I'm pessimistic.
There is no way
of just not writing the info? gdalinfo (and qgis) would automatically
calculate it if missing:
"-stats
Read and display image statistics. Force computation if no statistics
are stored in an image.
"
Thanks,

Agus



More information about the R-sig-Geo mailing list