Description Usage Arguments Value Methods Note Author(s) References See Also Examples
sample point locations within a square area, a grid, a polygon, or on a spatial line, using regular or random sampling methods; the methods used assume that the geometry used is not spherical, so objects should be in planar coordinates
1 2 3 
x 
Spatial object; 
... 
optional arguments, passed to the appropriate 
n 
(approximate) sample size 
type 
character; 
bb 
bounding box of the sampled domain; setting this to a smaller value leads to subregion sampling 
offset 
for regular sampling only: the offset (position) of the regular
grid; the default for 
cellsize 
if missing, a cell size is derived from the sample size

nsig 
for "pretty" cell size; 
pretty 
logical; if 
an object of class SpatialPointsclass. The number of
points is only guaranteed to equal n
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 Spatialclass for which
no spsamplemethods 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.
sample in the bbox of x
sample on a line
sample in a Polygon
sample in a Polygons object, consisting of possibly
multiple Polygon objects (holes must be correctly defined, use checkPolygonsHoles
if need be)
sample in an SpatialPolygons object; sampling
takes place over all Polygons objects present, use subsetting to vary
sampling intensity (density); holes must be correctly defined, use checkPolygonsHoles
if need be
sample in an SpatialGrid object
sample in an SpatialPixels object
If an Polygonclass object has zero area (i.e. is a line), samples on this line element are returned. If the area is very close to zero, the algorithm taken here (generating points in a square area, selecting those inside the polygon) may be very resource intensive. When numbers of points per polygon are small and type="random", the number searched for is inflated to ensure hits, and the points returned sampled among these.
The following two arguments can be further specified:
nclusters
Number of clusters (strata) to sample from.
iter
(default = 4) number of times to try to place sample points
in a polygon before giving up and returning NULL  this may occur when
trying to hit a small and awkwardly shaped polygon in a large bounding
box with a small number of points
Edzer Pebesma, [email protected]
Chapter 3 in B.D. Ripley, 1981. Spatial Statistics, Wiley
Fibonacci sampling: Alvaro Gonzalez, 2010. Measurement of Areas on a Sphere Using Fibonacci and LatitudeLongitude Lattices. Mathematical Geosciences 42(1), p. 4964
over, point.in.polygon, sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  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)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.