[GRASS-user] Re: mapcalc/mapcalculator in python script

Johannes Radinger JRadinger at gmx.at
Thu Feb 3 10:59:45 EST 2011

Hello Glynn,

Somehow I didn't your answer via email, I just found it at
I attached the text below.

Yes, I am sure, that I want to do the "if(B,C)" not e.g. "if(B,B,C)",
but anyhow...it doesn't work.... I  tried the **options version, but also no success. It seems that there is a bug in 6.5.

I've WinGrass 6.5SVN (http://grass.ibiblio.org/grass65/binary/mswindows/native/README.html) installed. I unistalled it and reinstalled it but still the same error. Everything else is working so far.

Maybe someone can reproduce my error, or tell me what I am doing wrong.

I am somehow depend on the 6.5 as on version 7 the r.stream.* module seems not to be integrated.

Any suggestions how to proceed?


Johannes Radinger wrote:

> I am running GRASS GIS 6.5 and want to run a python script
> including a mapcaluculator-expression of a simple formula:
> A=if(B,C)
> grass.mapcalc("$upstream_shreve = if(${upstream_part},${shreve})",
>                   upstream_shreve = options['upstream_shreve'],
>                   upstream_part = options['upstream_part'],
>                   shreve = options['shreve'])
> but that isn't working... I don't know whats excaclty the problem....

Are you sure you mean "if(B,C)" not e.g. "if(B,B,C)". The two argument
form returns the second argument if the first argument is nonzero and
zero if the the first argument is zero, i.e. "if(B,C,0)".

Other than that, the above should work; if it doesn't, that suggests a
bug somewhere (most of the Python code was written for 7.0 and
back-ported to 6.5; sometimes the code requires changes to work in

Also, if your variable names exactly match the keys in the options
dictionary, you can just pass the entire dictionary using Python's
"**" syntax, i.e.:

grass.mapcalc("$upstream_shreve = if(${upstream_part},${shreve})", **options)

Any extra options will be ignored.

GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

More information about the grass-user mailing list