xy_sample_random: Place a number of points randomly in a polygon of arbitrary...

Description Usage Arguments Details Value

View source: R/sampling_design.R

Description

Place a number of points randomly in a polygon of arbitrary shape

Usage

1
xy_sample_random(sp_poly, n, M = 1)

Arguments

sp_poly

An object of class SpatialPolygons from the sp package.

n

Sample size

M

Number of independent samples of size n

Details

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.

Value

A data.table object with M times n rows holding an identifier and xy-coordinates.


AWF-GAUG/fisim documentation built on May 28, 2019, 11:02 a.m.