rdomain: Draw uniformly distributed points from a set of areas

View source: R/domain.R

rdomainR Documentation

Draw uniformly distributed points from a set of areas

Description

An alternative to sf::st_sample which draws uniformly distributed points using a simple accept-reject method.

Usage

rdomain(n, dom, blocksize = n, itmax = Inf)

Arguments

n

Number of points desired in the final sample.

dom

An sf object representing a domain of areal units.

blocksize

Number of candidate points to draw on each pass of accept-reject sampling (see details). Defaults to n.

itmax

Maximum number of accept-reject samples to attempt. Defaults to Inf.

Details

Draws a sample of blocksize points uniformly from a bounding box on dom, and accepts only the points which belong to dom. This yields a uniform sample on dom. The process is repeated until n accepted draws are obtained, or until it has been attempted itmax times. If itmax iterations are reached without accepting n draws, an error is thrown.

This seems to be an order of magnitude faster than the current implementation of st_sample, although the latter can accomplish the same objective and is more general. The improved performance is worthwhile when used in the areal basis functions, which sample repeatedly from the domain.

Performance will degrade when areal units have small area relative to their bounding box, as many candidate points may need to be discarded. For example, this will occur if dom contains a set of small scattered islands in an ocean. In this case, it would be more efficient to sample from each island at a time.

Value

An sf object with 2-dimensional points.

Examples

dom = acs5_2013[c(1,5,8,12),]
pts = rdomain(10000, dom)


stcos documentation built on Aug. 21, 2023, 5:13 p.m.

Related to rdomain in stcos...