flightpathr

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

commit ed5b9602c10cfe5dcf4f024d2571a40c55d483d9
parent aefcef6a6a424bc893a967faeee9d463137ec3be
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Mon, 16 May 2016 10:51:10 -0400

Don't trust bearings for points within 1 mm.

Diffstat:
MR/coordsToBearing.R | 7+++++++
Mtests/testthat/test_coordsToBearing.R | 8++++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/R/coordsToBearing.R b/R/coordsToBearing.R @@ -16,5 +16,12 @@ coordsToBearing <- function(trajectory) { bearings <- geosphere::bearing(trajectoryCoords[1:(numPoints-1), 1:2], trajectoryCoords[2:numPoints, 1:2]) + + # If successive points have the SAME lon/lat, geosphere::bearing() produces + # meaningless output. Set these to NAs. + distancesMeters <- geosphere::distHaversine(trajectoryCoords[1:(numPoints-1), 1:2], + trajectoryCoords[2:numPoints, 1:2]) + bearings[distancesMeters < 1e-4] <- NA + return(c(bearings, NA)) } diff --git a/tests/testthat/test_coordsToBearing.R b/tests/testthat/test_coordsToBearing.R @@ -40,3 +40,11 @@ test_that("Trajectories are somewhat reversable", { expect_equal(destPoints[1:200], trajectory[1:200], tolerance = 1e-8) }) + +test_that("Repeated long/lats are handled correctly", { + trajectory <- geosphere::gcIntermediate(c(-119.841499, 34.426194), + c(-74.577166, 39.457583), + 100) + trajectory <- rbind(trajectory, trajectory[100, ], trajectory[100, ]) + expect_true(all(is.na(coordsToBearing(trajectory)[c(100, 101)]))) +})