有没有办法从 Rcpp 中读取栅格或 terra 对象的像元值?目前我将对象转换为向量并通过单元格(或行/列)访问:
RCPP:
#include <Rcpp.h>
// [[Rcpp::export]]
double value_from_cell(const Rcpp::NumericVector &x, const int cell) {
double out = x[cell-1];
return out;
}
回复:
library(terra)
# Create a SpatRaster from scratch
x <- rast(nrows = 108, ncols = 21, xmin = 0, xmax = 10,
vals = runif(108*21))
# Convert to vector
x_vec <- terra::values(x, mat = FALSE)
value_from_cell(x = x_vec, cell = 20)
我知道我可以通过fastizeize包Rcpp::S4
中的方式访问基本信息(例如 ncol、xmin、..) 。但是直接从 Rcpp 中读取值会很棒,因为转换为向量的 RAM 非常昂贵,甚至可能很大。任何帮助/指导都会很棒!