library(sf)
# define study area
sa <- suppressWarnings(st_cast(st_read(
system.file("shape/nc.shp",
package="sf")), "POLYGON"))
sa <- sa[10,]
# create "known" locations
locs <- st_sample(sa, 50)
st_crs(locs) <- st_crs(sa)
# systematic sample using extent polygon
e <- st_as_sf(st_as_sfc(st_bbox(sa)))
st_crs(e) <- st_crs(sa)
s <- background(e, p=1000, known=locs, d=1000)
plot(st_geometry(s), pch=20)
plot(st_geometry(locs), pch=20, col="red", add=TRUE)
# systematic sample using irregular polygon
s <- background(sa, p=1000, known=locs, d=1000)
plot(st_geometry(sa))
plot(st_geometry(s), pch=20, add=TRUE)
plot(st_geometry(locs), pch=20, col="red", add=TRUE)
# random sample using irregular polygon
s <- background(sa, p=500, known=locs,
d=1000, type="random")
plot(st_geometry(sa))
plot(st_geometry(s), pch=20, add=TRUE)
plot(st_geometry(locs), pch=20, col="red", add=TRUE)
Run the code above in your browser using DataLab