rdomain | R Documentation |
An alternative to sf::st_sample
which draws uniformly distributed
points using a simple accept-reject method.
rdomain(n, dom, blocksize = n, itmax = Inf)
n |
Number of points desired in the final sample. |
dom |
An |
blocksize |
Number of candidate points to draw on each pass of
accept-reject sampling (see details). Defaults to |
itmax |
Maximum number of accept-reject samples to attempt. Defaults
to |
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.
An sf
object with 2-dimensional points.
dom = acs5_2013[c(1,5,8,12),]
pts = rdomain(10000, dom)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.