Using tmaptools package in R - How can I extract the 'Bearing' information from a .GPX track file. This appears in Garmin Basecamp but does not appear using tmaptools::read_GPX. Currently I use the below code. But surely there is a simpler way? Link to GPS Track: https://www.dropbox.com/s/02p3yyjkv9fmrni/Barron_Thomatis_2019_EOD.gpx?dl=0
library(tmaptools)
library(tmap)
library(sf)
library(tidyverse)
library(geosphere)
GPSTrack <- read_GPX("Barron_Thomatis_2019_EOD.gpx", layers = "track_points", as.sf = TRUE)
#
#Adjust GPS Track Data
#
#Extract Lat & Lon from Track geometery (c(lat, Lon))
GPSTrack_Pts <- st_coordinates(GPSTrack)
#Add X, Y Columns to Track
GPSTrack2 <- cbind(GPSTrack, GPSTrack_Pts)
#Create a coordinate vector by combining X & Y
coords <- cbind(GPSTrack2$X,GPSTrack2$Y)
#Convert GPS Track into SpatialPoints format for calculating Bearing
GPSTrack_SpPts <- SpatialPoints(coords)
#Create GPS Point Bearing, GPP point distance & GPS Time interval columns
empty <- st_as_sfc("POINT(EMPTY)")
GPSTrack2 <- GPSTrack2 %>%
st_set_crs(4326) %>% # will use great circle distance
mutate(
Bearing = bearing(coords))
#Convert Bearing to Course and Add as column
GPSTrack2 <- GPSTrack2 %>%
mutate(course = (Bearing + 360) %% 360) # add full circle, i.e. +360, and determine modulo for 360