EVOLUTION-MANAGER
Edit File: spsample.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: sample point locations in (or on) a spatial object</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for spsample {sp}"><tr><td>spsample {sp}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> sample point locations in (or on) a spatial object </h2> <h3>Description</h3> <p> 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 </p> <h3>Usage</h3> <pre> spsample(x, n, type, ...) makegrid(x, n = 10000, nsig = 2, cellsize, offset = rep(0.5, nrow(bb)), pretty = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Spatial object; <code>spsample(x,...)</code> is a generic method for the existing <code>sample.Xxx</code> functions</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p> optional arguments, passed to the appropriate <code>sample.Xxx</code> functions; see NOTES for <code>nclusters</code> and <code>iter</code></p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p> (approximate) sample size </p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p> character; <code>"random"</code> for completely spatial random; <code>"regular"</code> for regular (systematically aligned) sampling; <code>"stratified"</code> for stratified random (one single random location in each "cell"); <code>"nonaligned"</code> for nonaligned systematic sampling (nx random y coordinates, ny random x coordinates); <code>"hexagonal"</code> for sampling on a hexagonal lattice; <code>"clustered"</code> for clustered sampling; <code>"Fibonacci"</code> for Fibonacci sampling on the sphere (see references).</p> </td></tr> <tr valign="top"><td><code>bb</code></td> <td> <p> bounding box of the sampled domain; setting this to a smaller value leads to sub-region sampling </p> </td></tr> <tr valign="top"><td><code>offset</code></td> <td> <p> for square cell-based sampling types (regular, stratified, nonaligned, hexagonal): the offset (position) of the regular grid; the default for <code>spsample</code> 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 <code>c(0.5,0.5)</code>, 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 </p> </td></tr> <tr valign="top"><td><code>cellsize</code></td> <td> <p> if missing, a cell size is derived from the sample size <code>n</code>; otherwise, this cell size is used for all sampling methods except <code>"random"</code> </p> </td></tr> <tr valign="top"><td><code>nsig</code></td> <td> <p> for "pretty" cell size; <code>spsample</code> does not result in pretty grids </p> </td></tr> <tr valign="top"><td><code>pretty</code></td> <td> <p>logical; if <code>TRUE</code>, choose pretty (rounded) coordinates</p> </td></tr> </table> <h3>Value</h3> <p> an object of class <a href="SpatialPoints-class.html">SpatialPoints-class</a>. The number of points is only guaranteed to equal <code>n</code> when sampling is done in a square box, i.e. (<code>sample.Spatial</code>). Otherwise, the obtained number of points will have expected value <code>n</code>. </p> <p>When <code>x</code> is of a class deriving from <a href="Spatial-class.html">Spatial-class</a> for which no <a href="spsample.html">spsample-methods</a> exists, sampling is done in the bounding box of the object, using <code>spsample.Spatial</code>. An overlay using <a href="over.html">over</a> may be necessary to select the features inside the geometry afterwards. </p> <p>Sampling type <code>"nonaligned"</code> is not implemented for line objects. </p> <p>Some methods may return NULL if no points could be successfully placed. </p> <p><code>makegrid</code> makes a regular grid that covers <code>x</code>; when <code>cellsize</code> 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. </p> <h3>Methods</h3> <dl> <dt>x = "Spatial"</dt><dd><p> sample in the bbox of <code>x</code> </p> </dd> <dt>x = "Line"</dt><dd><p> sample on a line </p> </dd> <dt>x = "Polygon"</dt><dd><p> sample in a Polygon </p> </dd> <dt>x = "Polygons"</dt><dd><p> sample in a Polygons object, consisting of possibly multiple Polygon objects (holes must be correctly defined, use <code>checkPolygonsHoles</code> if need be) </p> </dd> <dt>x = "SpatialPolygons"</dt><dd><p> 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 <code>checkPolygonsHoles</code> if need be </p> </dd> <dt>x = "SpatialGrid"</dt><dd><p> sample in an SpatialGrid object </p> </dd> <dt>x = "SpatialPixels"</dt><dd><p> sample in an SpatialPixels object </p> </dd> </dl> <h3>Note</h3> <p>If an <a href="Polygon-class.html">Polygon-class</a> 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. </p> <p>The following two arguments can be further specified: </p> <p><code>nclusters</code> Number of clusters (strata) to sample from. </p> <p><code>iter</code>(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 </p> <h3>Author(s)</h3> <p>Edzer Pebesma, <a href="mailto:edzer.pebesma@uni-muenster.de">edzer.pebesma@uni-muenster.de</a></p> <h3>References</h3> <p>Chapter 3 in B.D. Ripley, 1981. Spatial Statistics, Wiley </p> <p>Fibonacci sampling: Alvaro Gonzalez, 2010. Measurement of Areas on a Sphere Using Fibonacci and Latitude-Longitude Lattices. Mathematical Geosciences 42(1), p. 49-64 </p> <h3>See Also</h3> <p><a href="over.html">over</a>, <a href="point.in.polygon.html">point.in.polygon</a>, <a href="../../base/html/sample.html">sample</a></p> <h3>Examples</h3> <pre> 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) </pre> <hr /><div style="text-align: center;">[Package <em>sp</em> version 1.4-2 <a href="00Index.html">Index</a>]</div> </body></html>