[GRASS5] r.average, r.statistics

Glynn Clements glynn.clements at virgin.net
Sat Mar 2 20:09:41 EST 2002


Aleksey Naumov wrote:

> I have two maps: 'landuse' (CELL) and 'slope' (FCELL), and I need to average 
> 'slope' for every category in 'landuse'. Seems like r.average would do it, so 
> I do:
> 
> GRASS:~ > r.average base=landuse cover=slope output=landuse.slope
> 
> But:
> 
> 1) r.average help says:
> 
> "The output map is actually a reclass of the base map (see r.reclass), and 
> will have exactly the same category values as the base map. The averaged 
> values computed by r.average are stored in the output map's category labels 
> file."
> 
> But this is not what I see from r.info, r.report, r.cats! For example:

It appears that r.average was changed to use r.recode instead of
r.reclass when floating-point support was added. AFAIK, reclass maps
can only have integer values.

r.statistics *should* do it, but you note below that it doesn't.

You can extract the landuse/average-slope table from the computed
landuse.slope map with:

r.stats -1gn landuse | awk '{print $1,$2}' | r.what input=landuse,landuse.slope | awk -F'|' '{print $4,$5}' | uniq | sort | uniq

This is significantly less efficient (and more cumbersome) than the
original r.average.

You could modify r.average so that it doesn't delete the temporary
file ("tempfile2" variable) which contains the r.recode rules.

> Also:
> 
> 2) r.statistics is designed to do the same as r.average, r.mode, r.median, 
> etc. Why not deprecate r.average & others in favor of r.statistics? This 
> would reduce the number of modules, and I think that GRASS really needs this.
> 
> The long list of raster modules is confusing, especially given that too many 
> of them either duplicate each other, or don't work the way they are supposed 
> to (according to help). Well, you can see I've had a tough day with GRASS 
> today :-)
> 
> Is r.statistics supported though? I tried using it for the problem above, it 
> complained that r.stats doesn't accept <z> flag. Changed line 29 of 
> src/raster/r.statistics/cmd/o_average.c
> from 
> 	sprintf (command, "%s -az input='%s,%s' fs=space > %s", ... 
> to:
> 	sprintf (command, "%s -an input='%s,%s' fs=space > %s", ...
> 
> Now I can run it:
> GRASS:~ > r.statistics base=landuse cover=slope method=average output=landuse.slope1
> 
> but the output map 'landuse.slope1' is totally wrong. r.report says that all 
> it's cells are null, and r.info seems to get stuck in a loop and needs Ctrl-C.

If I try this using the landuse and slope maps from the "spearfish"
dataset, it works. r.info doesn't produce useful information, but
r.cats does.

I'll commit the "-z/-n" fix to r.statistics.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-dev mailing list