[GRASS-dev] r.mapcalc eval function: syntax and existing maps

Vaclav Petras wenzeslaus at gmail.com
Wed Jan 22 11:19:44 PST 2014


Hi,

I have two r.mapcalc problems to think about.

You probably remember Glynn's example of `eval` function usage in r.mapcalc
expression. The example is now in the manual and says:

r.mapcalc << EOF
eval(elev_200 = elevation - 200, \
     elev_5 = 5 * elevation, \
     elev_p = pow(elev_5, 2))
elevation_result_1 = (0.5 * elev_200) + 0.8 * elev_p
EOF

However, the function descriptions says that:

  eval([x,y,...,]z)       evaluate values of listed expr, pass results to z

And the section NULL support (btw, why this one?) says that:

  The eval() function always returns its last argument

So, as a consequence I tried this:

r.mapcalc << EOF
elevation_result_2 = eval(elev_200 = elevation - 200, \
     elev_5 = 5 * elevation, \
     aspect = pow(elev_5, 2), \
     (0.5 * elev_200) + 0.8 * aspect)
EOF

And it works.

The questions are now: Are both versions valid? And if yes, is one of them
best practice? And should both be in the manual?

The site note is that manual perhaps defines how the function/syntax
behaves but does not provide examples nor conclusion about what is allowed
and possible. In my opinion, manual should not require user to infer how to
use the module, it should show how to do it.

The second think to discuss is the behavior when you use name `aspect` in
the `eval` function, although the `aspect` map exists. I described the
behavior in r58765. Please review.

Vaclav


[r58765] https://trac.osgeo.org/grass/changeset/58765

[r.mapcalc] http://grass.osgeo.org/grass70/manuals/r.mapcalc.<http://grass.osgeo.org/grass70/manuals/r.mapcalc.html>

[GRASS-user] Trying to reclassify raster using non-linear functions in GRASS
http://lists.osgeo.org/pipermail/grass-user/2013-November/069225.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140122/562ab5d1/attachment.html>


More information about the grass-dev mailing list