[GRASS-user] r.mapcalc: columns()/modulo - rounding issue,
possible bugfeature ?
Glynn Clements
glynn at gclements.plus.com
Mon Feb 16 17:27:12 EST 2009
peter.loewe at gmx.de wrote:
> 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 ?
>
> The phenomenon can be reproduced by using the above mentioned
> r.mapcalc command, displaying the result as a cell values layer.
Please be more precise regarding the "displaying" part.
If I run:
r.mapcalc "modulo = (1 + ( col() % 4 ) )"
r.out.ascii modulo | head
I see what I expect, not what you describe.
OTOH, if you replace r.out.ascii with e.g. d.rast, the data will then
be resampled again according to the "screen" dimensions.
If you run d.rast from the command line, the default screen dimensions
are 640 x 480. With the default region for Spearfish of 634 x 477, the
resampling will be ever so slightly greater than 1:1, resulting in
occasional duplicates.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list