2

I simply cannot find out the following: I want to repeat a calculation in GRASS GIS several times. Is there a command for r.mapcalc to repeat a calculation x times (similar to this possibility in r.mfilter, for example)....besides listing that step x times in s shell scripts (I use shell).

6

You can call r.mapcalc in for loop. In shell it could look like this:

X=5
# initialize first map
r.mapcalc "old = 10"

# loop
for I in `seq $X` 
do
  r.mapcalc "new = old + 10" --overwrite
  g.rename rast=new,old --overwrite
done

In shell command seq 5 creates a sequence 1, 2, 3, 4 , 5.

Note that you shouldn't use r.mapcalc like this (read from and write in the same map):

r.mapcalc "old = old + 10" --overwrite
  • The loop in one line: for I in `seq $X`; do r.mapcalc "new = old + 10" --overwrite && g.rename rast=new,old --overwrite; done ;-) – Nikos Alexandris Dec 3 '14 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.