你可以使用spatstat 非常有效地做到这一点,如果可以
lat,lon 数据作为平面坐标。所以我们假设你没有越过日期线
(+/-180 度经度)并且 1 度纬度等于 1 度
经度。这仅在赤道附近是正确的。远离赤道的你
应该真正将其中一个坐标乘以适当的因子或
理想情况下,您应该将数据投影到平面坐标系。
随机生成 16 个站点和近 300 万深度的数据
测量下面找到最近邻居的代码不到一半
在我的笔记本电脑上一秒钟。
library(spatstat)
stations <- data.frame(stationID = 1:16,
Latitude = runif(16, 0, 10),
Longitude = runif(16, 0, 10))
Wstations <- bounding.box.xy(stations$Longitude, stations$Latitude)
Xstations <- ppp(stations$Longitude, stations$Latitude, window = Wstations)
N <- 2943485
depths <- data.frame(Longitude = runif(N, 0, 10),
Latitude = runif(N, 0, 10),
depth = runif(N, 0, 1000))
Wdepths <- bounding.box.xy(depths$Longitude, depths$Latitude)
Xdepths <- ppp(depths$Longitude, depths$Latitude, window = Wdepths)
id <- nncross(Xstations, Xdepths, what = "which")
stations$depths <- depths$depth[id]
head(stations)
#> stationID Latitude Longitude depths
#> 1 1 5.7992147 5.6716015 435.1266
#> 2 2 9.2218643 6.0519959 154.5833
#> 3 3 7.6444158 3.2228619 963.7626
#> 4 4 3.8993755 0.9428149 204.9189
#> 5 5 7.9673171 0.9801396 933.5696
#> 6 6 0.9453616 8.0829834 603.0325