View source: R/generate_points.R
generate_points | R Documentation |
Generates point coordinates over a rasterlayer extent.
generate_points(
raster,
approach = "grid",
n = NULL,
padding = 0,
try = NULL,
values = NULL,
patch_conditions = NULL,
trim = TRUE,
attempts = 10,
distance = NULL,
offset = FALSE,
closest_cell = FALSE,
parallel = FALSE,
cores = 1,
progress = TRUE
)
raster |
An object of class 'SpatRaster', 'RasterLayer', 'RasterStack' or 'RasterBrick'. |
approach |
One of the following: "grid" to generate points through a grid, "random" to generate points at random locations, or "patch" to generate points inside patches that meet pre-defined conditions. See Details. |
n |
Number of point to generate. |
padding |
Numeric. Width (in meters) of the internal margin around the raster that will be discarded from the analysis. See Details. |
try |
Number of points to be generated in
each turn. Only applies if |
values |
The values of the rasterlayer where points should be placed. Only applies if
|
patch_conditions |
The conditions that patches must meet to be included as the
patches from which points will be generated. Only applies if |
trim |
Logical. If TRUE (default) the number of final points will be trimmed to the value
defined in |
attempts |
Number of attempts to generate new random points given the total required
points ( |
distance |
Distance between points of the grid (if |
offset |
Logical. If TRUE, each point coordinates will be randomly displaced around the area
occupied by the raster cell size. If FALSE (default), each point will be located at the center of
a given raster cell. Only applies if |
closest_cell |
Logical. If |
parallel |
Logical. If TRUE, part of the processes will be parallelized. See Details. |
cores |
Number of cores to use if |
progress |
Logical. If TRUE (default), progress of the analysis will be printed. |
If approach = "random"
, the user can restrict the locations of new generated points
inside raster cells with certain value or values, by defining them in values
. Also a minimum distance
between the generated points can be defined in distance
(also applies for the resolution of
the grid if approach = "grid"
).
If approach = "random"
and a minimum distance was defined, the function will generate new
"random" points in sequential passes. In each pass, the function will try to generate new points
taking into account the minimum distance between points, by randomly generating a number of points as
defined in try
. The function will perform this task until the new generated points is equal or
higher than n
. If try = NULL
(default), try
will equals n
. If in each turn no new points
were added (i.e. new points were located at less than the minimum distance to other previously
generated points), the function will record this event. If this event happens more than the
number of times defined in attempts
before the total generated points equals n
, the function will
terminate, and return the points that were successfully generated given the required parameters.
The user may try different values for n
, try
and attempts
to get a desirable result.
If approach = "patch"
, the function will return as many points as patches that meet certain
conditions in relation to pre-defined metric values. Conditions can be defined in
argument patch_conditions
, for which the helper function conditions()
is available:
conditions(list(class, metric, minimum value, maximum value), list(class, metric, minimum value, maximum value), ...)
class: the class (raster value) of the patch that must meet the defined conditions. More than one class can be specified.
metric: the patch-level metric whose values must meet the defined conditions. Only one metric
per condition can be defined. Available patch-level metrics can be found in metrics_list()
and in
documentation of the package landscapemetrics
.
minimum value: the minimum value that the metric must have for the retained patches. If equal to -Inf, and a maximum value is defined, patches whose values in the defined metric are equal or lower to the maximum value will be retained.
maximum value: the maximum value that the metric must have in the retained patches. If equal to Inf, and a minimum value is defined, patches whose values in the defined metric are equal or higher to the minimum value will be retained.
Retained patches will be those patches that meet all patch conditions at the same time. Returned
point's coordinates will equal the centroid of each patch. If closest_cell = TRUE
, the point's coordinates of the
centroids that did not fall inside the patch will be moved to the closest cell belonging to that
patch.
To avoid generating points to close to the boundaries of the raster, the outer borders of the
raster can be discarded from the analysis, by considering the width inputted in padding
.
If parallel = TRUE
the function will parallelize part of the processes. Parallelization
is done to obtain the coordinates of the patches if approach = "patch"
. The number of
cores must be declared in cores
(parallelization requires at least two cores). To use this
functionality, package parallel
must be installed. So far, parallelization will run
in LINUX and MAC, but not in Windows.
An object of class 'SpatVector' containing the coordinates of the generated points.
mland()
# Loads raster
elchaco <- terra::rast(system.file("extdata", "elchaco.tif", package = "multilandr"))
# Returns points at "random" locations, but inside cells of value equals to 1.
chaco_coords <- generate_points(elchaco, approach = "random", values = 1, n = 500)
# The same but points must be separated by at least 300 m between each other. Also, each point
# is randomly displaced inside the raster cell.
chaco_coords2 <- generate_points(elchaco, approach = "random", values = 1, n = 500,
try = 100, distance = 300, offset = TRUE)
# Returns as many points as patches that meet the defined condition. This is
# all patches of value equal to 1 of area between 9 and 11 hectares.
patch_sites <- generate_points(elchaco, approach = "patch",
patch_conditions = conditions(list(1, "area", 8, 12)),
padding = 2000)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.