从经度和纬度计算角度 [英] Calculating angle from latitude and longitude
问题描述
我有一组经度和纬度,所以这是动物随时间移动的数据.我想做的是计算转弯角度,即每次运动之间转过的角度.所以说我有点1,点2和点3,分别对应每个点的经度和纬度值(动物从点1到点2到点3等),我想计算这3个点之间的角度2是中间点.我应该怎么办?我的操作系统是Windows,我正在使用R进行分析.
I have a set of latitudes and longitudes , so this is the data for an animal as it moves in time. what i want to do is to calculate turning angle, that is by what angle it turns between every movement. so say i have point 1, point 2 and point 3 with latitude and longitude value corresponding to each point(animal moves from point 1 to point 2 to point 3 and so on) and i want to calculate the angle between these 3 points, point 2 being the middle point. what should i do? my OS is windows and i am using R for analysis.
这是我的示例数据:
longitude latitude
36.89379547 0.290166977
36.89384037 0.290194109
36.88999724 0.286821044
36.88708721 0.288339411
36.88650313 0.29010232
36.88563203 0.289939416
36.88545224 0.290924863
它们以十进制度为单位
推荐答案
使用maptools
中的trackAzimuth
函数:
library(maptools)
trackAngle <- function(xy) {
angles <- abs(c(trackAzimuth(xy), 0) -
c(0, rev(trackAzimuth(xy[nrow(xy):1, ]))))
angles <- ifelse(angles > 180, 360 - angles, angles)
angles[is.na(angles)] <- 180
angles[-c(1, length(angles))]
}
trackAzimuth
函数是围绕 gzAzimuth
的简单循环包装.有关在球体上计算方向的参考,请参见?gzAzimuth
.
The trackAzimuth
function is a simple loop wrapper around gzAzimuth
. See ?gzAzimuth
for references on calculating directions on the sphere.
使用数据:
x <- read.table(text = "longitude latitude
36.89379547 0.290166977
36.89384037 0.290194109
36.88999724 0.286821044
36.88708721 0.288339411
36.88650313 0.29010232
36.88563203 0.289939416
36.88545224 0.290924863", header = TRUE)
trackAngle(as.matrix(x))
[1] 10.12946 111.17211 135.88514 97.73801 89.74684
我不得不从函数中删除第一个/最后一个角度,这是我在其他地方使用此函数之后所做的事情.应该是现在.:)
I had to remove first/last angles from the function, something I was doing after the fact with this function elsewhere. Should be right now. :)
此外,软件包 adehabitatLT
和 argosfilter
包含用于计算轨迹方向和角度的函数.
Also, the packages adehabitatLT
and argosfilter
contain functions to calculate track directions and angles.
这篇关于从经度和纬度计算角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!