View source: R/subsample.distance.R
subsample.distance | R Documentation |
Draws a minimum, and optional maximum constrained, distance sub-sampling
subsample.distance(x, size, d, d.max = NULL, replacement = FALSE)
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 |
A subsampled POLYGON or POINT sf object
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).
Jeffrey S. Evans <jeffrey_evans@tnc.org>
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")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.