library(sf)
if(require(spatstat.explore, quietly = TRUE)) {
data(bei, package = "spatstat.data")
trees <- st_as_sf(bei)
trees <- trees[-1,]
n=round(nrow(trees) * 0.10, digits=0)
trees.wrs <- pp.subsample(trees, n=n, window='hull')
plot(st_geometry(trees), pch=19, col='black')
plot(st_geometry(trees.wrs), pch=19, col='red', add=TRUE)
box()
title('10% subsample')
legend('bottomright', legend=c('Original sample', 'Subsample'),
col=c('black','red'),pch=c(19,19))
} else {
cat("Please install spatstat.explore package to run example", "\n")
}
Run the code above in your browser using DataLab