[GRASS-user] Set raster value for specific cell

Hi,

is there a simple way to set the value of a specific raster cell (e.g. defined by the coordinate of its cell center). One way could be to define a point by the coordinates (e.g. v.in.ascii) and then to convert the point to raster (v.to.rast) and use the mapcalculator to modify the original raster with the help of this new-point raster…

…But is there a simpler way to “call” the raster-cell directly?

/Johannes

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

Cheers,

Paulo

···

On 05/13/2013 11:56 AM, Johannes Radinger wrote:

Hi,

is there a simple way to set the value of a specific raster cell (e.g. defined by the coordinate of its cell center). One way could be to define a point by the coordinates (e.g. v.in.ascii) and then to convert the point to raster (v.to.rast) and use the mapcalculator to modify the original raster with the help of this new-point raster…

…But is there a simpler way to “call” the raster-cell directly?

/Johannes

_______________________________________________
grass-user mailing list
[grass-user@lists.osgeo.org](mailto:grass-user@lists.osgeo.org)
[http://lists.osgeo.org/mailman/listinfo/grass-user](http://lists.osgeo.org/mailman/listinfo/grass-user)

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@gclements.plus.com>

Johannes Radinger wrote:

is there a simple way to set the value of a specific raster cell (e.g.
defined by the coordinate of its cell center). One way could be to define a
point by the coordinates (e.g. v.in.ascii) and then to convert the point to
raster (v.to.rast) and use the mapcalculator to modify the original raster
with the help of this new-point raster...

...But is there a simpler way to "call" the raster-cell directly?

Just for the records, there is also d.rast.edit, very handy for hand-crafting
pixel values :slight_smile:

Regards, Nikos