set_points | R Documentation |
This function simulates point patterns in space and rasterize them. The idea is to mimic the spatial distribution of point-type infrastructure, such as houses, cabins, or turbines, for instance. The function returns a list with the position of the points and a binary raster with 1 where there are points and NA elsewhere. If created with a raster to define the weights, this base raster is also returned in the output.
set_points(
n_features = 1000,
method = c("mobsim", "regular", "random", "raster")[1],
centers = 1,
width = 0.05,
base_raster = NULL,
point_coordinates = NULL,
res = 0.1,
extent_x = c(0, 1),
extent_y = c(0, 1),
buffer_around = 0,
return_base_raster = TRUE,
use_terra = TRUE,
crs = ""
)
n_features |
|
method |
|
centers |
|
width |
|
base_raster |
|
point_coordinates |
|
res |
|
extent_x , entent_y |
|
buffer_around |
|
return_base_raster |
|
use_terra |
|
crs |
|
If method = "mobsim"
, the function builds upon the function
mobsim::sim_thomas_community()
from the mobsim
package. Originally the function is intended to simulate positions of multiple
species in the context of species abundance distribution studies, but it fits
well in case of a single species (or point patterns for a single type of feature).
In this case, the points are simulated based on the number of centers/patches of points
and their width.
If method = "raster"
, the function uses an input raster (defined by the argument
base_raster
) to define the probabilities of setting a given point in a certain pixel
in space.
A list with three elements: (1) pts
, the coordinates (x,y) of the simulated points;
(2) rast
, a binary raster containing the landscape, with 1 where there points and NA elsewhere;
(3) base_rast
, the base raster used to weigh the simulation of points. If method = "mobsim"
or "regular"
or "random"
, base_rast
is NULL
.
#-----
# using mobsim
library(terra)
library(mobsim)
set.seed(1234)
# gradient distribution
ext <- 30000
wd <- ext/5
pts <- set_points(n_features = 1000, centers = 1,
width = wd, res = 100,
extent_x = c(0, ext), extent_y = c(0, ext))
plot(pts$pts)
plot(pts$rast, col = "black")
# one focus of features, with buffer around
wd <- ext/20
pts <- set_points(n_features = 1000, centers = 1,
width = wd, res = 100,
extent_x = c(0, ext), extent_y = c(0, ext),
buffer_around = 10000)
plot(pts$pts)
plot(pts$rast, col = "black")
#-----
# using base raster
# raster
set.seed(12)
r <- raster::raster(matrix(runif(12),3,4)) |>
raster::disaggregate(fact = 10)
# points from raster
pts <- set_points(n_features = 100, method = "raster",
base_raster = r)
plot(pts$base_rast)
plot(pts$pts)
plot(pts$rast, col = "black")
#-----
# using random or regular
set.seed(123)
ext <- 30000
pts <- set_points(n_features = 1000, method = "random",
res = 100,
extent_x = c(0, ext), extent_y = c(0, ext))
plot(pts$pts)
plot(pts$rast, col = "black")
pts <- set_points(n_features = 1000, method = "regular",
res = 100,
extent_x = c(0, ext), extent_y = c(0, ext))
plot(pts$pts)
plot(pts$rast, col = "black")
#-----
# using point coordinates as input
pt_input <- data.frame(x = c(0.5, 0.7), y = c(0.5, 0.3))
pts <- set_points(point_coordinates = pt_input)
plot(pts$pts)
plot(pts$rast, col = "black")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.