Learn R Programming

spatialEco (version 1.1-1)

subsample.distance: Subsample distances

Description

Minimum, and optional maximum, distance constrained sub-sampling

Usage

subsample.distance(x, n, d, d.max = NULL, replacement = FALSE,
  latlong = FALSE, trace = FALSE)

Arguments

x

A spatial polygons or points sp object

n

Number of random samples drawn from x

d

Minimum sample distance

d.max

Maximum sample distance (not used unless specified

replacement

(FALSE/TRUE) sample with or without replacement

latlong

(FALSE/TRUE) is the data in a geographic projection (latitude/longitude)

trace

(FALSE/TRUE) Print min and max sample distances

Value

A sp spatial object, of the same class as x containing the random sub-samples

Examples

Run this code
# NOT RUN {
  library(sp)
  data(meuse)
    coordinates(meuse) <- ~ x+y
  
  # Subsample with a 500m minimum sample spread 
  sub.meuse <- subsample.distance(meuse, n = 10, d = 500, trace = TRUE)  
    plot(meuse,pch=19, main="min dist = 500")
      points(sub.meuse, pch=19, col="red") 
  
  # Check distances	
  dm <- spDists(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")  
    
# }
# NOT RUN {
  # Subsample with a 500m minimum and 3500m maximum sample spread   
  sub.meuse <- subsample.distance(meuse, n = 10, d = 500, d.max = 3500)  
    plot(meuse,pch=19, main="min dist = 500, max dist = 3500")
      points(sub.meuse, pch=19, col="red") 

  # Check distances		
  dm <- spDists(sub.meuse)
    diag(dm) <- NA
  cat("Min distance for subsample", min(dm, na.rm=TRUE), "\n")  
  cat("Max distance for subsample", max(dm, na.rm=TRUE), "\n")    
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab