我得到这个错误 “错误在.pointsToMatrix(P1):纬度> 90”。 谁可以解释为什么以及如何解决?
错误告诉你,你得到了纬度值大于90,这是超出范围:
library(geosphere)
distHaversine(c(4,52), c(13,52))
# [1] 616422
distHaversine(c(4,52), c(1,91))
# Error in .pointsToMatrix(p2) : latitude > 90
您可以只按所接受的范围内的坐标喂养distHaversine
解决这个问题。
我尝试使用R中的distHavrsine功能,一个循环里面 计算某些纬度和经度坐标之间的距离 了几百行。 (......),如果距离小于50米 我想它来记录这些行
看一看的distm
功能,轻松地计算出你的几百行的距离矩阵(即没有循环)。它默认使用distHaversine
。例如,为了获得更接近然后65万米数据帧行:
df <- read.table(sep=",", col.names=c("lon", "lat"), text="
4,52
13,52
116,39")
(d <- distm(df))
# [,1] [,2] [,3]
# [1,] 0 616422 7963562
# [2,] 616422 0 7475370
# [3,] 7963562 7475370 0
d[upper.tri(d, T)] <- NA
(idx <- which(d < 650000, arr.ind = T))
# row col
# [1,] 2 1
cbind(df[idx[, 1], ], df[idx[, 2], ])
# lon lat lon lat
# 2 13 52 4 52
请考虑提供一个小的可重复的例子的 – akrun
可能的复制[如何找到采用半正矢两个不同的数据帧之间的最近距离( https://stackoverflow.com/questions/44608687/how-to-find-the-nearest-distance-between-two-different-data-frames-using-haversi) –