[GRASS-dev] formatting expressions for r.mapcalc in GRASS6.4.3

Helena Mitasova hmitaso at ncsu.edu
Sat Feb 2 14:17:42 PST 2013


On Feb 2, 2013, at 8:27 AM, Glynn Clements wrote:

> 
> Helena Mitasova wrote:
> 
>> Over the years there have been changes in the formatting of r.mapcalc expressions
>> and it appears the currently there is no single way that would work everywhere
>> (you either need quotes or it does not work with quotes and in GRASS6.4.3 the space around = is not necessary).
>> I have tried to summarize our experience on MSWindows, Mac and linux here
>> 
>> http://courses.ncsu.edu/mea582/common/GIS_anal_grass/mapcalcformats.html
>> 
>> My question about the document above - is this how it should work?
> 
> From the command line, the most portable approach is to use:
> 
> 	r.mapcalc "outmap = whatever"
> 
> That should work in any version on any platform.

Glynn, Markus,

thanks for your answer - I have used your suggested format for years and that is how we have it in the book
and it works in linux shell and on my mac in command console as well - I will add it to my little how to run mapcalc document
given that it is still valid. 
But it does not work in command console in windows7, I had to remove the quotes to get it run. 
I should get more feedback from students by tuesday and I will try 
it in the lab again and post the error message - last two semesters, I guess since GRASS6.4.3svn there were more troubles 
with r.mapcalc than before, although the command console otherwise works really great.

BTW when you look at the Notes in the manual, the suggestion there is to put single quotes around the expression (right side of the equation), while the section about raster map layer names explains that putting your expression in double quotes will
interpret it as a raster map name and the floating point section has the quotes as used in the book so if somebody is new to GRASS 
it is easy to get confused. 

Helena
> 
> GRASS 6 simply concatenates all arguments with a space between each
> one, and uses the result as the expression.
> 
> GRASS 7 uses G_parser():
> 
> 	Usage:
> 	 r.mapcalc [expression=string] [file=name] [--overwrite] [--verbose]
> 	   [--quiet]
> 
> The above example is shorthand for:
> 
> 	r.mapcalc expression="outmap = whatever"
> 
> For this to work, the expression must be a single argument (i.e. 
> quoted), and there must be a space between the output map and the
> first "=". Using:
> 
> 	r.mapcalc "outmap=whatever"
> 
> would result in G_parser() complaining that "outmap" isn't a
> recognised option name.
> 
> -- 
> Glynn Clements <glynn at gclements.plus.com>



More information about the grass-dev mailing list