get_closest: Select points that most closely approximate the distribution...

View source: R/balance_around.R

get_closestR Documentation

Select points that most closely approximate the distribution of another set of points

Description

Sometimes you have a large collection of points which are not randomly distributed or spatially balanced and you would like a subset that more or less do. Given a template of points that are distributed the way you would like, this will return the closest existing point to each. This can be done taking into account membership in a group, either by having assigned it as a variable in both sets of points or by providing polygons that can be used to assign membership. By default, no stratification/membership is taken into account.

Usage

get_closest(
  existing_points,
  template_points,
  strata_polygons = NULL,
  stratafield = NULL,
  projection = "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0",
  iteration_limit = 5000
)

Arguments

existing_points

Point sf object. The points you would like to select from by comparing against template_points.

template_points

Point sf object. The points you would like to compare against existing_points in order to select a subset of those that most closely resemble the distribution of the template points.

strata_polygons

Optional polygon sf object. Polygons assigned a variable with a name stratafield that contains the membership information (e.g. strata) to assign to existing_points and template_points. If NULL then no assignment will be attempted. Defaults to NULL.

stratafield

Character string. If strata_polygons is not NULL, the name of the variable in strata_polygons that contains the membership information. Otherwise, the name of the variable in both template_points and existing_points that contains the membership information. If NULL then the points will be considered to belong to a single group. Defaults to NULL.

projection

Character string. The projection to force all spatial objects into. Defaults to NAD83, sp::CRS("+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0").

iteration_limit

Numeric. The maximum number of iterations to attempt to sort before giving up. Defaults to 5000.

Value

A spatial points data frame made by trimming existing_points down to the points that most closely approximate the distribution of template_points while also containing the same number of points as template_points. It will be in the projection specified by projection.


nstauffer/sample.design documentation built on May 9, 2022, 3:21 a.m.