[GRASSLIST:2088] Re: r.mapcalc questions
Glynn Clements
glynn.clements at virgin.net
Wed Dec 17 15:04:31 EST 2003
Miha STAUT wrote:
> I did not understand how the min, max, median and mode functions in
> r.mapcalc work
They take a variable number of arguments.
> (is there also a function the calculation of arithmetic
> averages? e.g. mean).
No, but it isn't much harder to write it out explicitly, e.g.:
(x1+x2+x3)/3
> I would only like to perform an operation like this:
>
> r.mapcalc "p=myrast1-min(myrast2)"
What do you mean by "min(myrast2)"? The minimum cell value occuring
within myrast2? If so, you can get this data from "r.info -r", e.g.
min=`r.info -r myrast2 | sed -n '/^min=/s///p'`
r.mapcalc "p=myrast1-$min"
> Is there any other way to insert some descriptive statistics into r.mapcalc
> directly?
r.mapcalc evaluates the expression(s) on a per-cell basis; it doesn't
compute aggregates over the entire map. For that, r.statistics is more
appropriate.
> How do I manage rasters with number names in r.mapcalc? E.g. ortophotos
> named with numbers. I tried the following:
> r.mapcalc "newrast=myrast-"40600370""# 40600370 is a raster layer
> But it still treats the name like a number.
Single and double quote characters are significant to the shell. To
get the right expression in to r.mapcalc you have to do one of the
following:
1. Run r.mapcalc without arguments and type the expression at the
prompt:
GRASS:~ > r.mapcalc
Enter expressions, "end" when done.
mapcalc> newrast=myrast-"40600370"
mapcalc> end
2. Store the expression in a file, and redirect r.mapcalc's input from
that file:
r.mapcalc < expression.txt
3. Use single quotes around the expression and double quotes within
it:
r.mapcalc 'newrast=myrast-"40600370"'
[The shell doesn't interpret double quotes (or anything else) within
single quotes.]
4. Use double quotes around the expression and single quotes within
it:
r.mapcalc "newrast=myrast-'40600370'"
[The shell doesn't interpret single quotes within double quotes;
however it still expands shell variables, so use this form if you need
to use shell variables within an expression.]
5. Use double quotes around the expression and "escape" any double
quotes in the expression with backslashes:
r.mapcalc "newrast=myrast-\"40600370\""
--
Glynn Clements <glynn.clements at virgin.net>
More information about the grass-user
mailing list