madi
April 11, 2009, 8:00pm
1
Hi all,
i'm in trouble using r.mapcalc in Grass 6.5 svn
In order to replace in a raster map (basin_10m) the values 24,26 with 28, i use the following cmd line:
r.mapcalc 'basin_10m_2=if(basin_10m==24),28'
r.mapcalc 'basin_10m_2=if(basin_10m==26),28'
the result is:
syntax error, unexpected ',', expecting $end
Parse error
which is the correct command to use?
Thank you in advance.
margherita
--
Ing. Margherita Di Leo
Ph.D. Student Methods and Technologies for Environmental Monitoring
Department of Environmental Engineering and Physics (DIFA)
University of Basilicata Campus Macchia Romana
85100 - Potenza Italy
Office: +39-0971205363
Fax: +39-0971205160
E-mail: dileomargherita AT gmail DOT com
Skype: dileomargherita
URL: http://www.difa.unibas.it/A_Manager_PP.do?azione=visualizzaHomePage&id=106
On Sat, Apr 11, 2009 at 10:00 PM, Margherita Di Leo <diregola@gmail.com> wrote:
Hi all,
i'm in trouble using r.mapcalc in Grass 6.5 svn
In order to replace in a raster map (basin_10m) the values 24,26 with 28, i
use the following cmd line:
r.mapcalc 'basin_10m_2=if(basin_10m==24),28'
r.mapcalc 'basin_10m_2=if(basin_10m==26),28'
You need to set the braces correctly (personally, I use
double quotes to be able to use shell variables). Also
better define the "else" part:
if(condition, then, else)
so
r.mapcalc "basin_10m_2=if(basin_10m==24, 28, null())"
r.mapcalc "basin_10m_3=if(basin_10m==26, 28, null())"
Note that I changed the second map name to _3 otherwise
it would overwrite the first.
You can also combine conditions, e.g.:
if(condition1 && condition2, then, else)
cheers
Markus
On Sat, Apr 11, 2009 at 10:29 PM, Margherita Di Leo <diregola@gmail.com> wrote:
Markus Neteler wrote:
On Sat, Apr 11, 2009 at 10:00 PM, Margherita Di Leo <diregola@gmail.com>
...
r.mapcalc "basin_10m_2=if(basin_10m==24, 28, null())"
r.mapcalc "basin_10m_3=if(basin_10m==26, 28, null())"
the matter is that i don't want to replace the whole map with null value , i
only want to replace 24 and 26 with 28 and preserve the other values of the
map.
Sure, then (to preserve, use the map name):
r.mapcalc "basin_10m_2=if(basin_10m==24, 28, basin_10m)"
r.mapcalc "basin_10m_3=if(basin_10m_2==26, 28, basin_10m_2)"
or simply
r.mapcalc "basin_10m_2=if(basin_10m==24 || basin_10m==26, 28, basin_10m)"
Markus