Given a Quadtree
, a set of points, and a vector of
new values, changes the value of the quadtree cells containing the points
to the corresponding value.
# S4 method for Quadtree,ANY,numeric
set_values(x, y, z)
A Quadtree
A two-column matrix representing point coordinates. First column contains the x-coordinates, second column contains the y-coordinates.
A numeric vector the same length as the number of rows of
y
. The values of the cells containing y
will be changed
to the corresponding value in z
.
no return value
Note that it is entirely possible for y
to contain multiple points
that all fall within the same cell. The values are changed in the order
given, so the cell will take on the last value given for that cell.
It's important to note that this modifies the original quadtree. If you wish
to maintain a version of the original quadtree, use copy
beforehand to make a copy of the quadtree.
transform_values()
can be used to transform the
existing values of all cells using a function.
library(quadtree)
habitat <- terra::rast(system.file("extdata", "habitat.tif", package="quadtree"))
# create a quadtree
qt <- quadtree(habitat, split_threshold = .1)
# generate some random points, then change the values at those points
ext <- extent(qt)
pts <- cbind(runif(100, ext[1], ext[2]), runif(100, ext[3], ext[4]))
set_values(qt, pts, rep(10, 100))
# plot it out to see what happened
old_par <- par(mfrow = c(1, 2))
plot(qt, main = "original")
plot(qt, main = "after modification")
par(old_par)