[GRASS-user] Assign random cell values (integers)

Rainer M Krug Rainer at krugs.de
Tue Oct 1 04:39:48 PDT 2013


Johannes Radinger <johannesradinger at gmail.com> writes:

> Hi,
>
> what is the most effective way to assign randomly
> the values -1,0 and 1 to a raster map, where each of
> the three values should occur in one third of the map.
>
> Furthermore I'd like to assign to 10 % of the cell
> the values -1 and 10% the value 1 and to the remaining
> 80% the value 0 (or any other arbitrary combination of

EXACTLY 10%, or with a probability of 10?

If EXACTLY, I guess you have to use different functions (select 10%
random cells, assign -1, mask them out, select again 10% of the ORIGINAL
NUMBER of cells, assigh=n 1, assgn 0 to the rest)

Otherwise, you can use the random() function in r.mapcalc:

r < 0.1 -> assign 1
r > 0.9 -> assign -1
otherwise assign 0

Hope this helps,

Rainer


> the three values). Is there any fast way in G7 or do I need
> to play with r.random, r.mask and r.mapcalc and r.patch.
> 
> Maybe someone has already had such a task...
> so any suggestion is welcome.
>
> cheers,
> Johannes
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com



More information about the grass-user mailing list