[GRASS-user] r.mapcalc: columns()/modulo - rounding issue, possible bugfeature ?

Moritz Lennert mlennert at club.worldonline.be
Mon Feb 16 11:04:55 EST 2009


On 16/02/09 15:31, peter.loewe at gmx.de wrote:
> Hi,
> 
> I stumbled over this "funny" behavior of the col() function of
> r.mapcalc (GRASS6.2 and GRASS6.4, both on Linux).
> 
> According to The Book, col() "returns current col of moving window".
> 
> I assume that for each row of a given raster layer col() should
> provide the values 1,2,3,4,5, etc. as it travels through the row.
> 
> To produce a map of repeating value sequences (for example the
> numbers 1 2 3 4 ) the module operator can be used on the
> col()-function:
> 
> col()  operator result 1      mod 4     = 1 2      mod 4     = 2 3
> mod 4     = 3 4      mod 4     = 0 5      mod 4     = 1 6      mod 4
> = 2 etc
> 
> this approach was put into mapcalc. The "1 + " makes sure that the
> sequence  runs from 1-4 not 0 - 3:
> 
> r.mapcalc modulo="(1 + ( col() % 4 ) )"
> 
> A map was produced in a Spearfish location (col() should operate
> independently from the projection).
> 
> Here it comes: For some (strange ?)reason, there are "ripples" in the
> "1 - 4" sequence.
> 
> Instead of going 1234 1234 1234 ad infinitum once in a while a number
> is omitted: 1234 1234 234  1234 134 etc.
> 
> Has anybody come across this behavior before ? Is this a
> feature/good-thing ?

After a little testing I come to the (preliminary) conclusion that this 
depends on whether the number of cols is divisable by 4, i.e. cols % 4 = 
0. If this is not the case, then you don't get the complete sequence. 
So, it depends on your region setting.

Moritz


More information about the grass-user mailing list