spsample                 package:sp                 R Documentation

_s_a_m_p_l_e _p_o_i_n_t _l_o_c_a_t_i_o_n_s _i_n (_o_r _o_n) _a _s_p_a_t_i_a_l _o_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

     sample point locations within a square area, a grid, a polygon, or
     on a spatial line, using regular or random sampling methods

_U_s_a_g_e:

     spsample(x, n, type, ...)
     sample.Spatial(x, n, type, bb = bbox(x), offset = runif(nrow(bb)), cellsize, ..., nclusters = 1)
     sample.Line(x, n, type, offset = runif(1), proj4string=CRS(as.character(NA)), ...)
     sample.Polygon(x, n, type = "random", bb = bbox(x), offset = runif(2), proj4string=CRS(as.character(NA)), iter = 4, ...)
     sample.Polygons(x, n, type = "random", bb = bbox(x), offset = runif(2), proj4string=CRS(as.character(NA)), iter = 4, ...)
     sample.Sgrid(x, n, type = "random", bb = bbox(x), offset = runif(nrow(bb)), ...)
     makegrid(x, n = 10000, nsig = 2, cellsize, offset = rep(0.5, nrow(bb)))

_A_r_g_u_m_e_n_t_s:

       x: Spatial object; 'spsample(x,...)' is a generic method for the
          existing 'sample.Xxx' fumctions

     ...: optional arguments, passed to the appropriate 'sample.Xxx'
          functions

       n: (approximate) sample size 

    type: character; '"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

      bb: bounding box of the sampled domain; setting this to a smaller
          value leads to sub-region sampling 

  offset: for regular sampling only: the offset (position) of the
          regular grid; the default for '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") 

cellsize: if missing, a cell size is derived from the sample size 'n';
          otherwise, this cell size is used for all sampling methods
          except '"random"' 

nclusters: Number of clusters (strata) to sample from

proj4string: Object of class '"CRS"'; holding a valid proj4 string

    nsig: for "pretty" coordinates; 'spsample' does not result in
          pretty grids 

    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

_V_a_l_u_e:

     an object of class SpatialPoints-class. 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 Spatial-class for which no
     spsample-methods exists, sampling is done in the bounding box of
     the object, using 'spsample.Spatial'. An overlay may be necessary
     to select 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, deriving cell size from the
     number of grid points requested (approximating the number of
     cells).

_M_e_t_h_o_d_s:


     _x = "_S_p_a_t_i_a_l" sample in the bbox of 'x' 

     _x = "_L_i_n_e" sample on a line 

     _x = "_P_o_l_y_g_o_n" sample in an Polygon 

     _x = "_P_o_l_y_g_o_n_s" sample in an Polygons object, consisting of
          possibly multiple Polygon objects (and holes!) 

     _x = "_S_p_a_t_i_a_l_P_o_l_y_g_o_n_s" sample in an SpatialPolygons object;
          sampling takes place over all Polygons objects present, use
          subsetting to vary sampling intensity (density) 

     _x = "_S_p_a_t_i_a_l_G_r_i_d" sample in an SpatialGrid object 

     _x = "_S_p_a_t_i_a_l_P_i_x_e_l_s" sample in an SpatialPixels object 

_N_o_t_e:

     If an Polygon-class 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.

_A_u_t_h_o_r(_s):

     Edzer J. Pebesma, edzer.pebesma@uni-muenster.de

_R_e_f_e_r_e_n_c_e_s:

     Chapter 3 in B.D. Ripley, 1981. Spatial Statistics, Wiley

_S_e_e _A_l_s_o:

     overlay-methods, point.in.polygon, sample

_E_x_a_m_p_l_e_s:

     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)

