To be able to use a raster as a template given the argument res, this raster can not be in a SpatRaster format. One sollution is simple and is to convert it to a RasterLayer with raster::raster().
This is a reproducible example to use the maximum height raster as a template for minimum heigh calculation:
library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg <- readLAScatalog(LASfile, select = "xyz", chunk_size = 140, chunk_buffer = 0)
opt_chunk_alignment(ctg) <- c(0,20)
plot(ctg, chunk = TRUE)
library(future)
plan(multisession, workers = 2)
m = pixel_metrics(ctg, ~max(Z), 20)
# Works
pixel_metrics(ctg, ~min(Z), m)
# Does not work
pixel_metrics(ctg, ~miin(Z), raster(m))
# Works
To be able to use a raster as a template given the argument
res
, this raster can not be in aSpatRaster
format. One sollution is simple and is to convert it to aRasterLayer
withraster::raster()
.This is a reproducible example to use the maximum height raster as a template for minimum heigh calculation: