Using a r.mapcalc expression in grass.mapcalc

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using a r.mapcalc expression in grass.mapcalc

Jenny Turner
I need to use this expression output=@input (input has labels and I want to export them so i need to do this). How can I do this in grass.mapcalc in Python? Does it accept @?
Thanks

_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: Using a r.mapcalc expression in grass.mapcalc

Glynn Clements

Jenny Turner wrote:

> I need to use this expression output=@input (input has labels and I want to
> export them so i need to do this). How can I do this in grass.mapcalc in
> Python? Does it accept @?

grass.mapcalc() is just a wrapper around r.mapcalc, so it supports
whatever r.mapcalc supports.

This:

        grass.mapcalc('output = @input')

will work, but you wouldn't normally hard-code map names in a script.

grass.mapcalc() uses Python's string.Template class to simplify using
variables in expressions. This:

        grass.mapcalc('$output = @$input', output = 'output', input = 'input')

is equivalent to the previous expression, but you can easily replace
the hard-coded names with variables, e.g.:

        grass.mapcalc('$output = @$input', output = output, input = input)

Passing parameters which aren't used in the string is harmless, so you
can use Python's "**" syntax to pass a dictionary of parameters, e.g.
the "options" dictionary obtained from grass.parser():

        grass.mapcalc('$output = @$input', **options)

The values of the output= and input= options will be substituted into
the expression.

--
Glynn Clements <[hidden email]>
_______________________________________________
grass-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-user