簡體   English   中英

Distm function 用於計算 R 中坐標之間的距離

[英]Distm function for calculate distance between coordinates in R

朋友們可以幫我計算距離,使用 distm function 下面的代碼。 我有兩個數據庫,一個包含屬性坐標,另一個包含行業坐標。 我想使用 distm function 來計算兩個基地之間的距離。 更准確地說,從屬性 1 到行業 1,從屬性 2 到行業 1,依此類推。 任何幫助表示贊賞。

非常感謝!

df<-structure(list(Properties = c(1,2,3,4), 
                     Latitude = c(-23.8, -23.8, -23.9, -23.9), 
                     Longitude = c(-49.6, -49.3, -49.4, -49.8), 
                     Waste = c(526, 350, 526, 469)), class = "data.frame", row.names = c(NA, -4L))

df1<-structure(list(Industry = c(1,2,3,4), Latitude = c(-23.4, -23.7, -23.4, -23.8), 
                     Longitude = c(-49.7, -49.4, -49.6, -49.7)), class = "data.frame", row.names = c(NA, -4L))

這應該有效:

library(geosphere)

distm(df[,c('Longitude','Latitude')],
      df1[,c('Longitude','Latitude')],
             fun=distVincentyEllipsoid)

         [,1]     [,2]     [,3]     [,4]
[1,] 45461.49 23203.37 44300.99 10190.84
[2,] 60243.58 15053.19 53852.61 40763.35
[3,] 63272.26 22151.07 59016.34 32505.87
[4,] 56308.59 46393.08 59016.34 15048.01

第一行表示屬性 1 與行業 1、2、3 和 4 之間的距離。

另請參閱此處:

Function 使用 R 計算兩點(緯度,經度)之間的地理空間距離

2個緯度/經度點(坐標)列表之間的地理/地理空間距離

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM