r - 在R中找到4个坐标的中点坐标
问题描述
首先感谢大家对我以前的问题的所有帮助。
我试图在下面寻找一个可以找到我的数据集中心坐标的函数:
df <- read.table(sep=",", col.names=c("Start_Latitude","Start_Longitude","End_Latitude", "End_Longitude"),text="43.9567343, -78.8571382, 43.9399364, -78.8497342")
Start_Latitude Start_Longitude End_Latitude End_Longitude
43.9567343 -78.8571382 43.9399364 -78.8497342
我试过这段代码,但它只计算从起始坐标到结束坐标的距离,我想找到中点坐标而不仅仅是距离。我的意思是我需要找到中点的经纬度。
#dd the distance as column in the dataframe
df1$dist <- distm(x = df[, c('Start_Longitude', 'Start_Longitude')],
y = df[, c('End_Longitude', 'End_Latitude')],
fun = distHaversine
)
我有这个数据集:
Start_Latitude Start_Longitude End_Latitude End_Longitude dist
43.9567343 -78.8571382 43.9399364 -78.8497342 13669708
反正有没有找到中点的纬度和经度?另外,我如何计算以公里为单位的距离。
先感谢您!
解决方案
这是一种方法geosphere::midPoint
:
library(geosphere)
data.frame(df,
dist = distHaversine(df[, c('Start_Longitude', 'Start_Latitude')],
df[, c('End_Longitude', 'End_Latitude')]) / 1000,
midPoint(p1 = df[, c('Start_Longitude', 'Start_Latitude')],
p2 = df[, c('End_Longitude', 'End_Latitude')]))
# Start_Latitude Start_Longitude End_Latitude End_Longitude dist lon lat
#1 43.95673 -78.85714 43.93994 -78.84973 1.96183 -78.85344 43.94834
推荐阅读
- jitsi-meet - jitsi 中没有选项录制会议
- javascript - 如何导出选定范围内单元格的属性
- python - 关于为什么我的代码停止工作的建议?
- functional-programming - 同时折叠和映射
- c# - 将pdf文件转换为blob c#
- swiftui - SwiftUI:将相同的修饰符应用于每个 Stack 元素
- python - SimpleItk 裁剪图像
- reactjs - 使用 setState 更新 React-Select 菜单?
- c++ - FindWindowA() 返回 0,当我使用 GetLastError() 检查错误代码时,它也是 0 (ERROR_SUCCESS)
- python - 查找包含多个名称的文件路径