as_raster {quadtree} | R Documentation |
Create a raster from a Quadtree
Description
Creates a SpatRaster
from a Quadtree
.
Usage
## S4 method for signature 'Quadtree'
as_raster(x, rast = NULL)
Arguments
x |
a |
rast |
a |
Details
Note that the value of a raster cell is determined by the value of the
quadtree cell located at the centroid of the raster cell - thus, if a raster
cell overlaps several quadtree cells, whichever quadtree cell the centroid of
the raster cell falls in will determine the raster cell's value. If no value
is provided for the rast
parameter, the raster's dimensions are
automatically determined from the quadtree in such a way that the cells are
guaranteed to line up with the quadtree cells with no overlap, thus avoiding
the issue.
Value
Examples
library(quadtree)
habitat <- terra::rast(system.file("extdata", "habitat.tif", package="quadtree"))
# create a quadtree
qt <- quadtree(habitat, split_threshold = .1, split_method = "sd")
rst1 <- as_raster(qt) # use the default raster
rst2 <- as_raster(qt, habitat) # use another raster as a template
old_par <- par(mfrow = c(2, 2))
plot(habitat, main = "original raster")
plot(qt, main = "quadtree")
plot(rst1, main = "raster from quadtree")
plot(rst2, main = "raster from quadtree")
par(old_par)