I have some tracking data and I want to calculate the bearing over the course of the track. For two points we can use function from the fossil
package:
# earth.bear(long1, lat1, long2, lat2)
earth.bear(-10.54427, 52.11112, -10.55493, 52.10944)
# 255.6118
However, this won't work for more than two points. Here's some sample data:
tracks <- read.table(text =
"latitude, longitude
52.111122, -10.544271
52.10944, -10.554933
52.108898, -10.558025
52.108871, -10.560946
52.113991, -10.582005
52.157223, -10.626506
52.194977, -10.652878
52.240215, -10.678817
52.26421, -10.720366
52.264015, -10.720642", header = TRUE, sep = ",")
Try this:
sum(
sapply(1:(nrow(tracks) - 1), function(i){
earth.bear(tracks$longitude[i], tracks$latitude[i],
tracks$longitude[i+1], tracks$latitude[i+1] )
})
)
# 2609.871
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With