subsample.distance {spatialEco} | R Documentation |
Distance-based subsampling
Description
Draws a minimum, and optional maximum constrained, distance sub-sampling
Usage
subsample.distance(x, size, d, d.max = NULL, replacement = FALSE)
Arguments
x |
A POLYGON or POINT sf object |
size |
Subsample size |
d |
Minimum sampling distance in meters |
d.max |
Maximum sampling distance in meters |
replacement |
(FALSE/TRUE) Subsample with replacement |
Value
A subsampled POLYGON or POINT sf object
Note
This function provides a distance constrained subsample of existing point or polygon data. Please note that units are in meters regardless of input CRS projection units (including lat/long).
Author(s)
Jeffrey S. Evans <jeffrey_evans@tnc.org>
Examples
if(require(sp, quietly = TRUE)) {
library(sf)
data(meuse, package = "sp")
meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992,
agr = "constant")
# Subsample with a 500m minimum sample spread
sub.meuse <- subsample.distance(meuse, size = 10, d = 500)
plot(st_geometry(meuse), pch=19, main="min dist = 500")
plot(st_geometry(sub.meuse), pch=19, col="red", add=TRUE)
# Check distances
dm <- st_distance(sub.meuse)
diag(dm) <- NA
cat("\n", "Min distance for subsample", min(dm, na.rm=TRUE), "\n")
cat("Max distance for subsample", max(dm, na.rm=TRUE), "\n")
} else {
cat("Please install sp package to run example", "\n")
}
[Package spatialEco version 2.0-2 Index]