[英]Inverse Distance Weighting : Error in spDists(s0, s) : ncol(x) == ncol(y) is not TRUE in package gstat
I wish to do some "simple" inverse distance weighing.我希望做一些“简单”的反距离称重。 In the past I have used the idw function in gstat but that stopped working.
过去我在 gstat 中使用过 idw function 但它停止工作。 I found an equivalent idw0 in the same package but I can not get that to work.
我在同一个 package 中找到了一个等效的 idw0,但我无法让它工作。 This example code should produce 50 estimates for z-hat at the 50 points in the unknown.df data frame.
此示例代码应在 unknown.df 数据帧的 50 个点处生成 50 个 z-hat 估计值。
library(gstat)
set.seed(1)
x<-runif(100,0,1)
y<-runif(100,0,1)
z<-runif(100,0,1)
known.df<-data.frame(x,y,z)
x<-runif(50,0,1)
y<-runif(50,0,1)
unknown.df<-data.frame(x,y)
idw<-idw0(z~1,known.df,unknown.df)
idw<-idw0(z~1,known.df,unknown.df,y=as.matrix(known.df$z))
This produces the errors这会产生错误
> idw<-idw0(z~1,known.df,unknown.df)
Error in spDists(s0, s) : ncol(x) == ncol(y) is not TRUE
> idw<-idw0(z~1,known.df,unknown.df,y=as.matrix(known.df$z))
Error in spDists(s0, s) : ncol(x) == ncol(y) is not TRUE
Y has length 50, but what is x? Y 的长度为 50,但 x 是什么?
Need to explicitly denote the coordinate fields.需要明确表示坐标字段。
library(gstat)
library(sp)
set.seed(1)
x<-runif(100,0,1)
y<-runif(100,0,1)
z<-runif(100,0,1)
known.df<-data.frame(x,y,z)
coordinates(known.df) = ~ x + y
x<-runif(50,0,1)
y<-runif(50,0,1)
unknown.df<-data.frame(x,y)
coordinates(unknown.df) = ~ x + y
idw<-idw0(z~1,known.df,unknown.df)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.