[GRASS-user] How to initialize raster maps.

Glynn Clements glynn at gclements.plus.com
Fri Dec 9 17:14:59 EST 2011


Marcello Gorini wrote:

> >> Inside a loop in a shell script, I keep incrementing the values of a
> >> raster map using r.mapcalc with some logical expressions.

Note that using the same map as both input and output results in
undefined behaviour. Even if it happens to work, there's no guarantee
that it will continue to work in future versions.

If you need to implement an iterative algorithm, you should generate a
new map, then replace the original with g.remove+g.rename afterwards.

> >> Ideally, I would like to initialize it as a raster with the same
> >> dimensions as my base map, but containing only zeros.
> >>
> >> In order to do that, I use the following expression:
> >>
> >> r.mapcalc "initialized_map=if(base_map>**999999,1,0)"

There is no point in referring to your original map in the r.mapcalc
expression; the result will always be created with the bounds and
resolution of the current region. AFAIK, the only modules which don't
behave this way are r.in.*, which create the output to match the size
of the input file.

> But there is no way to avoid r.mapcalc, is there?

I'm sure that there are other ways to create a map consisting of
zeros, but there's no reason to suspect that any of them will be
faster than r.mapcalc.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list