当我试图在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顺便说一句,该函数在循环之外运行正常,但我看不出导致问题的循环设置出了什么问题。
这个错误似乎是在尝试以这种方式显示数据时遇到的一个常见错误,并且与传递给antipodal的空值有关。我很难找到那些可能在我的数据中的东西。我删除了“to”和“from”相同/覆盖的目的地,这可能导致为大圆圈绘制的距离为0。据报道,这是一个类似错误的问题,所以在这里:
Antipodal error in Great Circles code
原始代码使用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.csv fsub.csv
https://github.com/GaryPate/R-Greatcircles/commit/e1149ccdb7ab13b89f5f11e8ebad66f26ec3e39b
非常感谢!
发布于 2016-07-31 04:22:26
这不是一个答案。但在这里发布只是为了能够格式化调试输出。你想做的是..。一些东西..。这里没有说明。air2的第一行和第二行都有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, ])发布于 2020-11-06 11:18:59
是的,我也遇到了这个警告。但是,在我仔细检查了我的数据集并确保边列表中的每个点都存在于经纬度节点集中之后,循环就顺利地工作了。这个问题可能是由于节点和边之间的数据不匹配造成的。
https://stackoverflow.com/questions/38672009
复制相似问题