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 _w_i_t_h_i_n _a _s_p_a_t_i_a_l _r_e_g_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     spsample(x, n, type, ...)
     sample.Spatial(x, n, type, bb = bbox(x), offset = runif(2), cellsize, ...)
     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)), ...)
     sample.Polygons(x, n, type = "random", bb = bbox(x), offset = runif(2), proj4string=CRS(as.character(NA)), ...)
     sample.Sgrid(x, n, type = "random", bb = bbox(x), offset = runif(2), ...)
     makegrid(x, n = 10000, nsig = 2, cellsize, offset = c(0.5,0.5), 
             type = "regular", ...)

_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"); or '"nonaligned"' for nonaligned
          systematic sampling (nx random y coordinates, ny random x
          coordinates) 

      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] \times [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"' 

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

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

_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.

_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

_A_u_t_h_o_r(_s):

     Edzer J. Pebesma, e.pebesma@geo.uu.nl

_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)

