[GRASS-dev] r.mapcalc bug on max and min?

Glynn Clements glynn at gclements.plus.com
Wed Oct 8 03:38:41 PDT 2014


Pietro wrote:

> Perhaps we could add two new functions, like: rmin and rmax that stay
> for range min and range max that give this information

It's not possible to implement these as functions within the current
structure of r.mapcalc.

r.mapcalc's functions take row buffers as inputs, and return (i.e. 
populate) a row buffer as output.

There's no way to write a function which takes a map name as input
(r.mapcalc doesn't have any data types except numbers). A map name
automatically evaluates to the map's contents.

IOW, for a function call such as "sqrt(input)", the function is called
for each row, with the current row of data as its input. The function
has no information on where those values came from (e.g. whether
directly from a map or from the result of some other function).

It would be more realistic to implement it as a modifier, e.g. 
min#input, similar to how colour-table lookups are performed. But that
creates issues of its own: what's the type? DCELL? Or the same as the
input? Is it the value for the map as a whole or do we need to invoke
r.univar (or embed r.univar into r.mapcalc or libraster)? Are we going
to add similar modifiers for all of the other useful statistics? For
arbitrary quantiles?

> do you think could be useful?

Not really. Just use r.info (or r.univar if you want the min/max for
the current region) and substitute the result into the expression.

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


More information about the grass-dev mailing list