[GRASS-user] Set raster value for specific cell
Glynn Clements
glynn at gclements.plus.com
Mon May 13 05:28:56 PDT 2013
Paulo van Breugel wrote:
> You can use r.mapcalc. If mymap is your raster layer and you want to
> change the raster cell at coordinates 52deg and 10deg, use
>
> r.mapcalc "mymap = if(x()==52.0 && y()==10.00, 1, mymap)" --replace
Comparing floating-point values with == is seldom a good idea.
Instead:
r.mapcalc "newmap = if(abs(x()-52.0)<0.001 && abs(y()-10.00)<0.001, 1, oldmap)"
The above assumes that you already know the cell's centre coordinates
to within the desired accuracy.
If you want to set the cell containing a specific point, and be sure
of setting exactly one cell when the point is on the boundary between
cells:
eval `g.region -g`
r.mapcalc "newmap = if(row()-1 == int(($n-10.0)/$nsres) && col()-1 == int((52.0-$w)/$ewres), 1, oldmap)"
This calculates the integer row/column indices for the desired cell
then compares the current row/column to these.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list