View source: R/set_points_from_raster.R
set_points_from_raster | R Documentation |
This function simulates point patterns in space using the values of an input raster as weights or probabilities for selecting a point in a given location. It was designed to simulate points based on neutral landscape models but it works with other input rasters as well.
set_points_from_raster(base_raster, n_features = 1000)
base_raster |
|
n_features |
|
The function works by first selecting random pixels in the landscape and finding their centers, then adding random variation within each pixel to define the final point locations. It was based on this StackExchange very useful answer from "Spacedman": https://gis.stackexchange.com/questions/224321/randomly-generate-points-using-weights-from-raster
TO IMPROVE: implement with terra package
A data.frame
with the (x,y) coordinates of the simulated points.
#-----
# minimal example
# example based on
# https://gis.stackexchange.com/questions/224321/randomly-generate-points-using-weights-from-raster
library(raster)
# raster
set.seed(12)
r <- raster::raster(matrix(runif(12),3,4))
# points
pts <- set_points_from_raster(r, n_features = 300)
# plot
raster::plot(r)
points(pts)
# with terra
r <- terra::rast(r)
# points
pts <- set_points_from_raster(r, n_features = 300)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.