flightpathr

Tools to analyze aircraft and flight path data.
git clone https://git.eamoncaddigan.net/flightpathr.git
Log | Files | Refs | README | LICENSE

commit a82806ce3b9a08a20581f37c5f2c141856522c0b
parent 691dfd75b97e68ec178ef8a9c7d71a2a325f0cd1
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Wed, 21 Sep 2016 12:50:38 -0400

coordsToBearing() dealing directly with lon/lat.

Diffstat:
Mman/coordsToBearing.Rd | 11++++++-----
Mtests/testthat/test_coordsToBearing.R | 22+++++++++++-----------
2 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/man/coordsToBearing.Rd b/man/coordsToBearing.Rd @@ -2,13 +2,14 @@ % Please edit documentation in R/coordsToBearing.R \name{coordsToBearing} \alias{coordsToBearing} -\title{Calculate the bearing between successive points in a trajectory.} +\title{Calculate the bearing between successive longitude/latitude points.} \usage{ -coordsToBearing(trajectory) +coordsToBearing(longitude, latitude) } \arguments{ -\item{trajectory}{A matrix or SpatialPoints object indicating the trajectory -of an aircraft.} +\item{longitude}{Latitude values.} + +\item{latitude}{Longitude values.} } \value{ The numeric vecotor giving the instantaneious bearing at each point @@ -16,6 +17,6 @@ The numeric vecotor giving the instantaneious bearing at each point trajectory, but the last element will be \code{NA}. } \description{ -Calculate the bearing between successive points in a trajectory. +Calculate the bearing between successive longitude/latitude points. } diff --git a/tests/testthat/test_coordsToBearing.R b/tests/testthat/test_coordsToBearing.R @@ -1,19 +1,19 @@ library(flightpathr) context("coordsToBearing") -test_that("Input checking works", { - expect_error(coordsToBearing(matrix(c(-74.577166, 39.457583), nrow = 1))) -}) - test_that("Equatorial routes have constant bearing", { trajectory1 <- cbind(longitude = seq(-180, 180, length.out = 100), latitude = 0) trajectory2 <- cbind(longitude = -74.6, latitude = seq(89, -89, length.out = 100)) - expect_equal(angleDiff(coordsToBearing(trajectory1), rep(90, 100)), + expect_equal(angleDiff(coordsToBearing(trajectory1[, "longitude"], + trajectory1[, "latitude"]), + rep(90, 100)), c(rep(0, 99), NA)) - expect_equal(angleDiff(coordsToBearing(trajectory2), rep(180, 100)), + expect_equal(angleDiff(coordsToBearing(trajectory2[, "longitude"], + trajectory2[, "latitude"]), + rep(180, 100)), c(rep(0, 99), NA)) }) @@ -22,17 +22,17 @@ test_that("Non-equatorial routes look OK", { c(-74.577166, 39.457583), 100) - expect_equal(coordsToBearing(trajectory)[1], + expect_equal(coordsToBearing(trajectory[, "lon"], trajectory[, "lat"])[1], geosphere::bearing(trajectory[1, ], trajectory[2, ])) - expect_equal(coordsToBearing(trajectory)[99], + expect_equal(coordsToBearing(trajectory[, "lon"], trajectory[, "lat"])[99], geosphere::bearing(trajectory[99, ], trajectory[100, ])) - expect_true(is.na(coordsToBearing(trajectory)[100])) + expect_true(is.na(coordsToBearing(trajectory[, "lon"], trajectory[, "lat"])[100])) }) test_that("Trajectories are somewhat reversable", { trajectory <- geosphere::destPoint(c(-119.841499, 34.426194), b = 68.4, d = seq(0, by = 40281.88, length.out = 100)) - bearings <- coordsToBearing(trajectory) + bearings <- coordsToBearing(trajectory[, "lon"], trajectory[, "lat"]) destPoints <- matrix(NA, nrow = 100, ncol = 2) destPoints[1, ] <- trajectory[1, ] for (r in seq(2,100)) { @@ -48,5 +48,5 @@ test_that("Repeated long/lats are handled correctly", { c(-74.577166, 39.457583), 100) trajectory <- rbind(trajectory, trajectory[100, ], trajectory[100, ]) - expect_true(all(is.na(coordsToBearing(trajectory)[c(100, 101)]))) + expect_true(all(is.na(coordsToBearing(trajectory[, "lon"], trajectory[, "lat"])[c(100, 101)]))) })