[R-sig-Geo] select random "blocks" from grid
Dylan Beaudette
dylan.beaudette at gmail.com
Wed Feb 27 08:06:49 CET 2008
Hi,
Is there a simple approach to selecting random "blocks" using the sp classes
and methods?
Say I have a 10x10 grid of polygons, and would like to randomly select 10 of
these, and save them to a new sp class (for later saving to GRASS, etc.). Is
there a simple approach to this?
I have tried something along the lines of accessing the polygons directly:
s <- sample(1:100, size=10)
# doesn't work
grid at polygons[[s]]
# sort of works... but how can I 'upgrade' the result back to a complete set
# of polygons which can be saved to GRASS?
apply(matrix(s), 1, function(i) grid at polygons[[i]])
Ultimately I would like to establish several randomly placed 100m x 100m
squares within a square region. Setting up a grid, and selecting random cells
seemed like a simple approach, but if there is a better one I would be happy
to hear about it!
I suppose that I could hand-make something that generates random points,
expands their geometry to 100x100 meters, and then tests to see if the
resulting rectangle falls completely within the region of interest. This
would work as a last resort-- surely there must be a cleaner approach within
the existing framework (I hope!).
Cheers,
Dylan
--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341
More information about the R-sig-Geo
mailing list