Learn R Programming

spatialEco (version 2.0-2)

subsample.distance: 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)

Value

A subsampled POLYGON or POINT sf object

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

Author

Jeffrey S. Evans <jeffrey_evans@tnc.org>

Examples

Run this code
     
# \donttest{
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")
}
# }

Run the code above in your browser using DataLab