在具有高数据分辨率的R编程中计算大圆弧距离

在具有高数据分辨率的R编程中计算大圆弧距离

本文介绍了在具有高数据分辨率的R编程中计算大圆弧距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R编程的新手,但我正在计算长途客机飞行的大圆距,因此我尝试了使用Fields包中的rdist.earth()sp包中的soDistsN1()和其他命令.另外,我在搜索中几乎已经用尽了Google.在Matlab中这样做很容易,但是我似乎在R中找不到方法.

I'm new to R programming but I'm calculating the great circle distance flown by a long haul airliner and I've tried rdist.earth() from the Fields package, soDistsN1() from the sp package and other commands. Plus I've pretty much exhausted Google in my search. It's easy to do this in Matlab but I can't seem to find a way in R.

问题是当我提高数据分辨率(计算出的航点数量)时,我的总距离变得一团糟.我猜是因为我总结了航路点之间的总距离.有任何想法吗?

The problem is when I increase the data resolution (amount of waypoints calculated) my total distance goes haywire. I'm guessing it is because of how I summarize the total distance between waypoints. Any ideas?

我尝试过的示例:

data <- read.csv("FDM_test_Flight.csv")
library(fields)
fix <- cbind(data$LON, data$LAT)
fix_2 <- window(fix, deltat=500) # every 500th position I have 25,540 position readings
gcd <- rdist.earth(fix_2, miles=FALSE, R=6371)
sum(gcd)

推荐答案

您可以使用像这样的大圆距离 ...

r <- 6371 # radius of the Earth
data <- read.csv("FDM_test_Flight.csv")

# Convert to radians and make two vectors of point A and point B
x <- length(data$LON)
lon <- data$LON[1:(x-1)] * pi/180
lat <- data$LAT[1:(x-1)] * pi/180
lon2 <- data$LON[2:x] * pi/180
lat2 <- data$LAT[2:x] * pi/180

#Calculate distances
dist <- sum(acos(sin( lat ) * sin( lat2 ) + cos( lat ) * cos( lat2 ) * cos( lon2 -lon ) ) * r )

由于r以Km为单位,因此您的大圆距离将为Km.

Since r is given in Km your great circle distances will be Km.

这篇关于在具有高数据分辨率的R编程中计算大圆弧距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 21:28