R-创建大圆库(geosphere)时if(对足(p1,p2))中的错误



当我试图在http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/。运行函数循环时遇到以下错误:

Error in if (antipodal(p1, p2)) { : missing value where TRUE/FALSE needed

顺便说一句,当函数在循环之外时,它可以运行,但我看不出循环的设置有什么问题导致了问题。

这种错误似乎是在尝试以这种方式显示数据时遇到的常见错误,并且与传递给反足的NULL值有关。如果这些可能在我的数据中,我很难找到。我已经删除了相同/重叠的"到"one_answers"从"目的地,这可能会导致为大圆绘制0距离。据报道,这是SO上类似错误的问题:

大圆码中的反足错误

原始代码使用SQL查询来为gcIntermediate组装表,但如果有人想运行代码并亲自查看,我已经将这些表写成了表。

library(maptools)
library(rgeos)
library(sp)
library(geosphere)

fsub = read.csv("fsub.csv")  
dfCord = read.csv("dfCord.csv")  
dfBind = cbind(as.numeric(dfCord$lon), as.numeric(dfCord$lat))
sp = SpatialPoints(dfBind)
plot(sp)

for (j in 1:length(fsub$MODE9)) {

    air1 <- dfCord[dfCord$sa2_main11 == fsub[j,]$O_SA2_11,]
    air2 <- dfCord[dfCord$sa2_main11 == fsub[j,]$D_SA2_11,]
    inter <- gcIntermediate(c(as.integer(air1[1,]$lon), as.integer(air1[1,]$lat)), c(as.integer(air2[1,]$lon), as.integer(air2[1,]$lat)), n=100, addStartEnd=TRUE)

    lines(inter, col="black")
}

数据文件可以在GIT上找到。

dfCord.csvfsub.csv

https://github.com/GaryPate/R-Greatcircles/commit/e1149ccdb7ab13b89f5f11e8ebad66f26ec3e39b

非常感谢!

这不是一个答案。但在这里发布只是为了能够格式化调试输出。你想。。。某物此处未说明。CCD_ 1的第一行和第二行都具有NA。

> which( is.na( geosphere:::.interm( c(as.integer(air1[1, ]$lon), as.integer(air1[1, 
+        ]$lat)), c(as.integer(air2[1, ]$lon), as.integer(air2[1, 
+        ]$lat) ) )
+ )
+ )
Error in if (antipodal(p1, p2)) { : missing value where TRUE/FALSE needed
> traceback()
2: geosphere:::.interm(c(as.integer(air1[1, ]$lon), as.integer(air1[1, 
       ]$lat)), c(as.integer(air2[1, ]$lon), as.integer(air2[1, 
       ]$lat)))
1: which(is.na(geosphere:::.interm(c(as.integer(air1[1, ]$lon), 
       as.integer(air1[1, ]$lat)), c(as.integer(air2[1, ]$lon), 
       as.integer(air2[1, ]$lat)))))
> which( is.na( antipodal( c(as.integer(air1[1, ]$lon), as.integer(air1[1, 
+        ]$lat)), c(as.integer(air2[1, ]$lon), as.integer(air2[1, 
+        ]$lat) ) )
+ ))
[1] 1
> c( c(as.integer(air1[1, ]$lon[1]), as.integer(air1[1, 
+        ]$lat)[1]), c(as.integer(air2[1, ]$lon[1]), as.integer(air2[1, 
+        ]$lat[1]) ) 
+ )
[1] 151 -33  NA  NA
> as.integer(air2[1, ]
+ )
[1] NA NA NA NA
> as.integer(air2[2, ])

是的,我也遇到了这个警告。但在我仔细检查了我的数据集并确保边列表中的每个点都存在于经纬度节点集中之后,循环工作得很顺利。这个问题可能是由于节点和边之间的数据不匹配造成的。

最新更新