Learn R Programming

SDraw (version 2.1.3)

hal.polygon: Draws a Halton Lattice sample from an area (polygon) resource.

Description

Draws a Halton Lattice sample from a SpatialPolygons* object.

Usage

hal.polygon(x, n, J = NULL, eta = c(1, 1), triangular = FALSE,
  bases = c(2, 3), init.n.factor = 1000)

Arguments

x

A SpatialPoints or SpatialPointsDataFrame object. This object must contain at least 1 polygon.

n

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

J

A 2X1 vector of base powers. J[1] is for horizontal, J[2] for vertical dimension. J determines the size and shape of the smallest Halton boxes. There are bases[1]^J[1] vertical columns of Halton boxes over x's bounding box, and bases[2]^J[2] horizontal rows of Halton boxes over the bounding box, for a total of prod(bases^J) total boxes. The dimension of each box is c(dx,dy)/(bases^J), where c(dx,dy) are the horizontal and vertical extents of x's bounding box. If J=NULL (the default), J is chosen so that approximately 1000*n Halton boxes are placed in the bounding box of polygons, each as square as possible and each containing one point,

eta

A 2X1 vector specifying the number of points to add in the horizontal and vertical dimensions of each Halton box. e.g., if eta = c(3,2), a grid of 3 (horizontal) by 2 (vertical) points is added inside each Halton box.

triangular

A boolean scalar. If TRUE, odd horizontal rows of the Halton lattice are moved one-quarter a Halton box width to the right, while even rows of the Halton lattice are moved one-quarter of a Halton box width to the left. This creates a triangular Halton lattice over the bounding box of the polygons. If FALSE, a rectangular Halton lattice is constructed.

bases

2X1 vector of Halton bases. These must be co-prime.

init.n.factor

A scalar factor controlling the approximate number of points in the Halton lattice to place inside the polygons before sampling. If J is not specified, approximately init.n.factor*n points are placed in the Halton lattice overlaid on the polygons of x. Points in the Halton lattice are then sampled using the HAL method for points. init.n.factor*n is the approximate frame size.

Value

A SpatialPointsDataFrame containing locations in the HAL sample, in HAL order. Attributes of the sample points are:

  • sampleID: A unique identifier for every sample point. This encodes the HAL order. return[order(return$sampleID),] will sort the returned object in HAL order.

  • HaltonIndex: The index of the Halton box containing the point. This column is not, in general, unique. Points with the same HaltonIndex are in the same Halton box, and are "close" in space.

  • geometryID: The ID of the polygon in x containing each sample point. 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., "HAL").

  • J: Exponents of the bases used to form the lattice of Halton boxes. This is either the input J, or the J vector computed by halton.lattice.

  • bases: Bases of the Halton sequence used to draw the sample.

  • eta: the eta vector used in the lattice.

  • hl.box: The bounding box around points in x used to draw the sample. See halton.indices.

  • triangular: Whether the underlying lattice is triangular or square.

  • random.start: The random seed of the Halton lattice sample. See hal.point.

Details

A brief description of Halton Lattice sampling for polygons: Given a set of Halton Lattice parameters J, bases, eta, and triangular, the bounding box around all polygons is partitioned using a Halton lattice of prod(bases^J) boxes, each containing prod(eta) points. Points not inside at least one polygon are dropped. All this is done by halton.lattice.polygon. The resulting points (the Halton lattice frame) are passed to hal.point and sampled using the HAL method for points.

See Also

hal.line, hal.point, spsample

Examples

Run this code
# NOT RUN {
samp <- hal.polygon( WA, 100, J=c(4,3) )
plot(WA)
points( samp, pch=16, col="red" )
  
#   Different lattice topology
samp <- hal.polygon( WA, 100, J=c(8,2), eta=c(2,1), triangular=TRUE)
points( samp, pch=15, col="blue")
  

# }

Run the code above in your browser using DataLab