spsample(x, n, type, ...)
makegrid(x, n = 10000, nsig = 2, cellsize, offset = rep(0.5, nrow(bb)),
pretty = TRUE)
spsample(x,...)
is a generic method for the
existing sample.Xxx
fumctionssample.Xxx
functions; see NOTES for nclusters
and iter
"random"
for completely spatial random;
"regular"
for regular (systematically aligned) sampling;
"stratified"
for stratified random (one single random location in
each "cell"); "nonaligned"
for nonaligned systematic sampling
(nx random y coordinates, ny random x coordinates); "hexagonal"
for sampling on a hexagonal lattice; "clustered"
for clustered sampling;
"Fibonacci"
for Fibonacci sampling on the sphere (see references).spsample
methods is a random location in
the unit cell [0,1] x [0,1], leading to a different grid after
each call; if this is set to c(0.5,0.5)
, the returned grid is
not random (but, in Ripley's wording, "centric systematic"). For
line objects, a single offset value is taken, where the value varies within
the [0, 1] interval, and 0 is the beginning of each Line object, and 1
its end n
; otherwise, this cell size is used for all sampling methods
except "random"
spsample
does not result in
pretty grids TRUE
, choose pretty (rounded) coordinatesn
when sampling is done in a
square box, i.e. (sample.Spatial
). Otherwise, the obtained number
of points will have expected value n
.When x
is of a class deriving from Spatial-class for which
no spsample-methods exists, sampling is done in the bounding box
of the object, using spsample.Spatial
. An overlay using
over may be necessary to select the features inside the geometry
afterwards.Sampling type "nonaligned"
is not implemented for line objects.Some methods may return NULL if no points could be successfully placed.makegrid
makes a regular grid that covers x
; when
cellsize
is not given it derives one from the number of grid
points requested (approximating the number of cells). It tries to
choose pretty cell size and grid coordinates.x
checkPolygonsHoles
if need be) checkPolygonsHoles
if need be Fibonacci sampling: Alvaro Gonzalez, 2010. Measurement of Areas on a Sphere Using Fibonacci and Latitude-Longitude Lattices. Mathematical Geosciences 42(1), p. 49-64
data(meuse.riv) meuse.sr = SpatialPolygons(list(Polygons(list(Polygon(meuse.riv)), "x"))) plot(meuse.sr) points(spsample(meuse.sr, n = 1000, "regular"), pch = 3) plot(meuse.sr) points(spsample(meuse.sr, n = 1000, "random"), pch = 3) plot(meuse.sr) points(spsample(meuse.sr, n = 1000, "stratified"), pch = 3) plot(meuse.sr) points(spsample(meuse.sr, n = 1000, "nonaligned"), pch = 3) plot(meuse.sr) points(spsample(meuse.sr@polygons[[1]], n = 100, "stratified"), pch = 3, cex=.5) data(meuse.grid) gridded(meuse.grid) = ~x+y image(meuse.grid) points(spsample(meuse.grid,n=1000,type="random"), pch=3, cex=.5) image(meuse.grid) points(spsample(meuse.grid,n=1000,type="stratified"), pch=3, cex=.5) image(meuse.grid) points(spsample(meuse.grid,n=1000,type="regular"), pch=3, cex=.5) image(meuse.grid) points(spsample(meuse.grid,n=1000,type="nonaligned"), pch=3, cex=.5) fullgrid(meuse.grid) = TRUE image(meuse.grid) points(spsample(meuse.grid,n=1000,type="stratified"), pch=3,cex=.5)