Fwd: [GRASS-user] use pi number

José María Michia jose.maria.michia at gmail.com
Sat Aug 23 21:14:35 EDT 2008

2008/8/23 José María Michia <jose.maria.michia en gmail.com>:

>> Is it possible to define variables?

2008/8/23 Glynn Clements <glynn en gclements.plus.com>:

> Yes; an assignment anywhere other than at the top level will define a
> variable rather than an output map. You can either place the
> assignment at the point that you would first use the value, e.g.:
>        outmap = a * (pi = 3.14159265358979323846) + b
> or use eval(), e.g.:
>        outmap = eval(pi = 3.14159265358979323846, a * pi + b)

Thank you, Glynn. I was able to assign the variable.

> Variables remain in scope until the end of the file.

I do not know if I understood well about the scope of the variable. If
I need to use the variable in several maps, only works if Pi is
defined in each operation. For example:

This works:

r.mapcalc '= eval (pi = 3.14159265, pi + sin (map / pi))'
r.mapcalc 'b = eval (pi = 3.14159265, pi + cos (map / pi))'

But this does not:

r.mapcalc '= eval (pi = 3.14159265, pi + sin (map / pi))'
r.mapcalc 'b = eval (pi + cos (map / pi))'

Just out of curiosity: I searched on Google and documentation GRASS
how to do this, and could not find it. Does anyone know where it is
documented that?

Thanks again!
José María

PS: In response to messages from Glynn I forgot to use the address of
the group, so we forwarded those messages here. Sorry!

More information about the grass-user mailing list