[GRASS-user] grass.script.raster.mapcalc and multiple computations

Nikos Alexandris nik at nikosalexandris.net
Sat Oct 31 10:03:43 PDT 2015


Panagiotis Mavrogiorgos:

> Hi everyone,

Hi Pano!


> Is it possible to perform multiple computations using
> grass.script.raster.mapcalc()? What I want is to run something like this
> (example taken from r.mapcalc documentation):
> 
> r.mapcalc <<EOF
> > $GIS_OPT_OUTPUT.r = r#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 -
> > .$GIS_OPT_PERCENT) * r#$GIS_OPT_SECOND
> > $GIS_OPT_OUTPUT.g = g#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 -
> > .$GIS_OPT_PERCENT) * g#$GIS_OPT_SECOND
> > $GIS_OPT_OUTPUT.b = b#$GIS_OPT_FIRST * .$GIS_OPT_PERCENT + (1.0 -
> > .$GIS_OPT_PERCENT) * b#$GIS_OPT_SECOND
> > EOF

I think I'd use `eval`, see:

- <https://grass.osgeo.org/grass70/manuals/r.mapcalc.html#eval-function>
- <http://grass.osgeo.org/uploads/grass/history_docs/mapcalc-algebra.pdf>,
  always worth studying (pages 14 and on)
 
> When I give an expression as a multiline string, I get an error like this
> one:
> 
> Invalid map <i>
> > Parse error
> > ERROR: parse error
> > ERROR: An error occurred while running r.mapcalc


What is the exact expression?

Nikos


More information about the grass-user mailing list