Reputation: 113
I have GPS data and I am trying to calculate the bearing to the furthest part of the trip. My data looks like this:
Time Lat Long 18:11:25 -38.621449 142.931061 18:13:25 -38.62212 142.929871 18:15:33 -38.623333 142.92868 ... 23:16:26 -38.793068 142.827881 23:18:54 -38.795414 142.838516 23:23:02 -38.795803 142.839066 ... 09:59:49 -38.621532 142.930786
I am trying to calculate the bearing between the starting point (-38.621449 142.931061) and the furthest point (-38.793068,142.827881).
I have been able to do this by manually extracting the 2 locations from the spreadsheet and calculating the bearing using my script:
` bearing <- function(lat1,lon1,lat2,lon2){
lat1 <- angledim(lat1,"degrees","radians")
lon1 <- angledim(lon1,"degrees","radians")
lat2 <- angledim(lat2,"degrees","radians")
lon2 <- angledim(lon2,"degrees","radians")
dlon <- lon1 - lon2
theta <- atan2(cos(lat2)*sin(dlon),cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(dlon))
theta <- angledim(theta,"radians","degrees")
theta <- (theta+360) %% 360
theta
}`
Is there an easier way to calculate this without going through endless spreadsheets?
(Apologies in advance if things are not formatted properly, this is my first question!)
Thanks!
Upvotes: 1
Views: 92
Reputation: 1441
I'm using the earth.bear function from the fossil package here but you could use your own custom written one.
earth.bear(mydata$Long[1],mydata$Lat[1],
tail(mydata$Long, n=1),tail(mydata$Lat, n=1))
Upvotes: 1