[GRASS-user] Need help with figuring out how to use category values and labels with r.statistics

Glynn Clements glynn at gclements.plus.com
Tue Dec 9 01:29:41 EST 2008


William Hudspeth wrote:

> I am having a bit of a problem figuring out how to solve a processing
> flow:
> 
> I am starting out with a raster with a continuous distribution of float
> values. I want to calculate some basic descriptive statistics using
> r.statistics, but do not want to lose the important numeric information
> following the decimal point in the cell values. Because r.statistics
> only works on integer raster maps, I have first multiplied the float
> maps by a constant (e.g. 10,000), with the hopes that I can later divide
> by that constant to retain the figures following the decimal point.
> 
> e.g.
> 
> r.mapcalc integer_map=int(float_map*10000)
> 
> I have a raster map of state county id numbers that I use in the
> r.statistics calculation - the aim is to generate basic summary stats
> (e.g. mean) for each county
> 
> e.g.
> 
> r.statistics base=county_ids cover=integer_map output=mean_by_county
> method=average
> 
> The output map has category values set to the county IDs, and category
> labels set to the means by county (multiplied by the constant 10000). So
> far, so good.
> 
> To get back to a mean of the original values, I would like to divide
> these output maps by the constant (10000.00) using r.mapcalc, but doing
> so yields the category values (county IDs) divided by 10000, with empty
> category labels (losing the statistical information). If I use the -c
> argument in r.statistics (which uses the category labels in the
> calculation), I end up with the correct category labels (county IDs),
> but I will have lost all of the statistical information.
> 
> How do I get back to my original values (dividing by the constant of
> 10000) without losing the county id category labels with which they are
> associated?

If you just want to adjust the category labels, use e.g.:

	r.category mean_by_county | awk -vOFS=: '{print $1,$2/10000}' > cats
	r.category mean_by_county rules=cats

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list