commit f624ff46dfbe3f66a1d7caedef663f4bf65df726
parent e4df477e28518a1c99f8b8f9b3bc7827c916d384
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date: Wed, 21 Sep 2016 13:17:49 -0400
coordsToBearing() takes lon/lat pairs for real.
Diffstat:
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/R/coordsToBearing.R b/R/coordsToBearing.R
@@ -1,18 +1,15 @@
-#' Calculate the bearing between successive points in a trajectory.
+#' Calculate the bearing between successive longitude/latitude points.
#'
-#' @param trajectory A matrix or SpatialPoints object indicating the trajectory
-#' of an aircraft.
+#' @param longitude Latitude values.
+#' @param latitude Longitude values.
#' @return The numeric vecotor giving the instantaneious bearing at each point
#' along the trajectory, in degrees. This will have the same length as the
#' trajectory, but the last element will be \code{NA}.
#'
#' @export
-coordsToBearing <- function(trajectory) {
- trajectoryCoords <- get3dCoords(trajectory)
+coordsToBearing <- function(longitude, latitude) {
+ trajectoryCoords <- cbind(longitude, latitude)
numPoints <- nrow(trajectoryCoords)
- if (numPoints < 2) {
- stop("At least two time points must be specified")
- }
bearings <- geosphere::bearing(trajectoryCoords[1:(numPoints-1), 1:2],
trajectoryCoords[2:numPoints, 1:2])