[GRASS-dev] r.mapcal and python

Moritz Lennert mlennert at club.worldonline.be
Mon Nov 10 10:30:50 EST 2008


On 10/11/08 15:36, Roberto Antolí­n wrote:
> Hi all,
> I'm a python newbie so have some patience :-)
> 
> I'm trying to use r.mapcal with the grass.py function 'run_command' in 
> this way:
> 
> e = "%s=%s-%s" % (out, dsm, dtm)
> grass.run_command('r.mapcalc', expression = e)
> 
> However, the new raster in "%out" doesn't appear, and a new raster 
> called 'expression' is created instead.
> 
> I also tried with:
> 
> grass.run_command('r.mapcalc', expression = "%s=%s-%s" % (out, dsm, dtm))

The expression= parameter only exists in GRASS7, but not in grass6.x.

So, r.mapcalc expression=k=1

will give you

in GRASS6.x: a map called 'expression' with the value 1

in GRASS7: a map called 'k' with the value 1

So everything depends on the version of GRASS you are running.

> 
> with the same result. And also with:
> 
> grass.run_command('r.mapcalc', %s = "%s-%s" % (out, dsm, dtm))

No expert, but shouldn't this be:

grass.run_command('r.mapcalc', "%s = %s-%s" % (out, dsm, dtm))

[note the changed location of the opening quote]

Moritz


More information about the grass-dev mailing list