我尝试使用“xyz”阅读风格构建一个 2 层的 SpatRast。它使用 3 列作为 rast 函数的输入,但我收到一条包含 4 列的警告消息:
> rast(as.matrix(data.frame(x=c(1,1,2,2),y=c(1,2,1,2),z1=1:4)),type="xyz")
class : SpatRaster
dimensions : 2, 2, 1 (nrow, ncol, nlyr)
resolution : 1, 1 (x, y)
extent : 0.5, 2.5, 0.5, 2.5 (xmin, xmax, ymin, ymax)
coord. ref. :
data source : memory
names : z1
min values : 1
max values : 4
> r=rast(as.matrix(data.frame(x=c(1,1,2,2),y=c(1,2,1,2),z1=1:4,z2=5:8)),type="xyz")
Warning message:
In v[cells] <- xyz[, 3:d[2]] :
number of items to replace is not a multiple of replacement length
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
这是一个问题,我刚刚修复了它;我现在得到:
library(terra)
#terra version 1.0.0
m <- cbind(x=c(1,1,2,2), y=c(1,2,1,2), z1=1:4, z2=5:8)
r <- rast(m, type="xyz")
values(r)
# z1 z2
#[1,] 2 6
#[2,] 4 8
#[3,] 1 5
#[4,] 3 7
Run Code Online (Sandbox Code Playgroud)
和
as.data.frame(r, xy=TRUE)
# x y z1 z2
#1 1 2 2 6
#2 2 2 4 8
#3 1 1 1 5
#4 2 1 3 7
Run Code Online (Sandbox Code Playgroud)
感谢您报告此事。(如果您非常确定某件事是错误,那么更好的报告位置是这里)