Learn R Programming

SDraw (version 2.1.13)

srs.polygon: Draws a Simple Random Sample (SRS) from an area resource (polygons).

Description

Draws a simple random sample from a SpatialPolygons or SpatialPolygonsDataFrame object.

Usage

srs.polygon(x, n)

Arguments

x

A SpatialPolygons or SpatialPolygonsDataFrame object. This object must contain at least 1 polygon. If it contains more than 1 polygon, the SRS sample is drawn from the union of all polygons. Holes are respected.

n

Sample size. Number of locations to draw from the union of all polygons contained in x.

Value

A SpatialPointsDataFrame containing locations in the SRS sample, in arbitrary order. Attributes of the sample points (in the embedded data frame) are as follows:

  • sampleID: A unique identifier for every sample point.

  • geometryID: The ID of the polygon in x which each sample point falls. The ID of polygons in x are row.names(geometry(x)).

  • Any attributes of the original polygons (in x).

Additional attributes of the output object, beyond those which make it a SpatialPointsDataFrame, are:

  • frame: Name of the input sampling frame.

  • frame.type: Type of resource in sampling frame. (i.e., "polygon").

  • sample.type: Type of sample drawn. (i.e., "SRS").

Details

The SRS sample is drawn by generating uniform random deviates for coordinates in the bounding box surrounding polygons (e.g., c(xmin, ymin) + c(dx,dy)*runif(2)), tossing locations outside polygons until the required number is achieved.

See Also

bas.polygon, sss.polygon, hip.polygon, sdraw

Examples

Run this code
# NOT RUN {
# A square grid oriented east-west
WA.samp <- srs.polygon( WA, 100 )   
plot( WA )
points( WA.samp, pch=16 )


# }

Run the code above in your browser using DataLab