Description Usage Arguments Details Value
View source: R/sampling_design.R
Place a number of points randomly in a polygon of arbitrary shape
1 | xy_sample_random(sp_poly, n, M = 1)
|
sp_poly |
An object of class |
n |
Sample size |
M |
Number of independent samples of size |
Points are selected following a solution that was presented at a discussion on stackoverflow.com (https://stackoverflow.com/questions/11178414/algorithm-to-generate-equally-distributed-points-in-a-polygon).
In a first step the provided polygon is divided into non-overlapping triangles and the area of each triangle is calculated. To select one point randomly, one triangle with points P1, P2, P3 is sampled proportional to its area. Once the triangle is selected, a point P4 is placed randomly along an arbitrary edge of the triangle using uniform probabilities (in this implementation it's always the edge between P1 and P2). The final random point within the triangle is generated by chosing a random point along the edge between P3 and P4 using non-uniform probabilities.
This procedure is repreated until the desired number of points was generated.
A data.table
object with M
times
n
rows holding an identifier and xy-coordinates.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.