library(sf)
if(require(sp, quietly = TRUE)) {
data(meuse, package = "sp")
meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992,
agr = "constant")
xy <- meuse[2,]
rs100 <- sample.annulus(xy, r1=50, r2=100, size = 50)
rs200 <- sample.annulus(xy, r1=100, r2=200, size = 50)
plot(st_geometry(rs200), pch=20, col="red")
plot(st_geometry(rs100), pch=20, col="blue", add=TRUE)
plot(st_geometry(xy), pch=20, cex=2, col="black", add=TRUE)
legend("topright", legend=c("50-100m", "100-200m", "source"),
pch=c(20,20,20), col=c("blue","red","black"))
# \donttest{
# Run on multiple points
rs100 <- sample.annulus(meuse[1:3,], r1=50, r2=100,
size = 50)
rs200 <- sample.annulus(meuse[1:3,], r1=50, r2=200,
size = 50)
plot(st_geometry(rs200), pch=20, col="red")
plot(st_geometry(rs100), pch=20, col="blue", add=TRUE)
plot(st_geometry(meuse[1:3,]), pch=20, cex=2, col="black", add=TRUE)
legend("topright", legend=c("50-100m", "100-200m", "source"),
pch=c(20,20,20), col=c("blue","red","black"))
# }
} else {
cat("Please install sp package to run example", "\n")
}
Run the code above in your browser using DataLab