[GRASS-user] Select random cells from map

Hi there
I need to randomly select non-null cells from a given map. I tried r.random.cells but I cannot define a maximum number random cells and some selected random cells are not valid values in my map. is there any other function to randomly select cells from a raster?

Thanks
Antonio

__________ Information from ESET NOD32 Antivirus, version of virus signature database 5161 (20100601) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António Rocha:
Hi there
I need to randomly select non-null cells from a given map. I tried
r.random.cells but I cannot define a maximum number random cells and
some selected random cells are not valid values in my map. is there any
other function to randomly select cells from a raster?

Hello Antônio,

This one I think I can help.
There is this command "v.random" that allows you to create a vector
containing random points in your current region. And you can control the
number of points with the parameter "n". Than you can upload the vector
database with values from any raster with the command "v.what.rast" and than
export it to a file if you want.

The manual has this clarifying example:

v.random output=random_samples n=20
v.db.addtable map=random_samples layer=1 columns='cat INTEGER, sample DOUBLE
PRECISION'
v.what.rast vector=random_samples raster=elevation.10m@PERMANENT layer=1
column=sample

However, I believe that if you have null cells in your raster and some of
the random points happen to fall over them, you will have less valid points
than you expect, so I would say that you should check the resultant
database.

Hope this helps.
Best regards,

Marcello.

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Select-random-cells-from-map-tp5125298p5125703.html
Sent from the Grass - Users mailing list archive at Nabble.com.

Hi. I missed that r.random :slight_smile: It seems to do what I need. I just need to understand a bit more what is the COVER parameter
Thanks nikos

Nikos Alexandris wrote:

António Rocha:
  

Hi there
I need to randomly select non-null cells from a given map. I tried
r.random.cells but I cannot define a maximum number random cells and
some selected random cells are not valid values in my map. is there any
other function to randomly select cells from a raster?
    
Doesn't "r.random" (not "r.random.cells") work? I think it works on/for non-
NULL cells.

In case r.random.cells and its capabilities are required, couldn't you just create a non-NULL MASK and limit its operation as you wish?

Nikos

__________ Information from ESET NOD32 Antivirus, version of virus signature database 5163 (20100601) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 5163 (20100601) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

António wrote:

I need to randomly select non-null cells from a given map.
I tried r.random.cells but I cannot define a maximum number
random cells and some selected random cells are not valid
values in my map. is there any other function to randomly
select cells from a raster?

r.to.vect to get a vector area coverage of your raster (do
not use the -s flag), then v.random.cover from wiki addons
then v.to.rast, and finally r.mapcalc to transfer values from
source map to random cell map? (probably we/I should make a
new wrapper script to do that automatically)

or you might skip the last steps and just use v.random.cover's
raster= option to sample the raster map directly.

probably the best idea is to fix r.random's cover= option to
loop until it has enough points.

also if you will be doing a lot of geostats it is probably
worth your while to learn about the GRASS<->R interface:
http://grass.osgeo.org/wiki/R_statistics

... then the world is open to you.

good luck,
Hamish

Marcello wrote:

However, I believe that if you have null cells in your
raster and some of the random points happen to fall over
them, you will have less valid points than you expect, so
I would say that you should check the resultant database.

see http://grass.osgeo.org/wiki/GRASS_AddOns#v.random.cover

Hamish