[GRASS5] r.average, r.statistics

Glynn Clements glynn.clements at virgin.net
Sun Mar 3 20:43:46 EST 2002


Aleksey Naumov wrote:

> > > 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.
> 
> Yes, I just found out that r.statistics works fine when cover is CELL, but it 
> generates a null map when cover is a FCELL map. Try this in spearfish:
> 
> r.slope.aspect elevation=elevation.dem slope=slope.f format=percent
> r.statistics base=landuse cover=slope.f method=average output=landuse.slope
> 
> Then landuse.slope is all null as shown by r.report.
> 
> Obviously, it's a bug in r.statistics. I'll try to look at it, but would 
> appreciate any hints...

It's basically an artifact of the way that r.statistics works. 
r.statistics invokes r.stats with the base and cover maps, then
processes the output using the fact that r.stats' output is sorted in
order of the categories from the first map (the base map).

r.stats essentially works on categories. With an FP map, it partitions
the map's range into bands, and treats each band as a category. The
output format shows the band's range instead of an individual value,
and this confuses r.statistics.

To get FP maps to work, start by changing the r.stats command from
something like:

    sprintf (command, "r.stats -an input='%s,%s' fs=space > %s",
	basemap, covermap, tempfile1);

to something like:

    sprintf (command, "r.stats -1n input='%s,%s' fs=space | sort -n | awk '{print $1,$2,1}' > %s",
	basemap, covermap, tempfile1);

You will also need to change the processing loop to use float/double
instead of integer for the second column ("covercat" variable).

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



More information about the grass-dev mailing list