flightconflicts

Tools to analyze conflicts between aircraft.
git clone https://git.eamoncaddigan.net/flightconflicts.git
Log | Files | Refs | README | LICENSE

commit 67059fc085cc432d0485dcbc3b3aca1208ab5fd8
parent 4ee3b6c94a29f814d2095fb5cd11667b2278cdd9
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Fri, 20 May 2016 13:46:35 -0400

Fixed and passing tests.

Diffstat:
MR/lonlatToXY.R | 18+++++++++++-------
Atests/testthat/test_lonlatToXY.R | 17+++++++++++++++++
2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/R/lonlatToXY.R b/R/lonlatToXY.R @@ -10,19 +10,23 @@ lonlatToXY <- function(longitude, latitude, originLongitude, originLatitude) { # This implementation is based on code from: # http://williams.best.vwh.net/avform.htm#flat - dlon <- longitude - originLongitude - dlat <- latitude - originLatitude + lon0 <- originLongitude * pi / 180.0 + lat0 <- originLatitude * pi / 180.0 + + dlon <- longitude * pi / 180.0 - lon0 + dlat <- latitude * pi / 180.0 - lat0 # Radius in feet and flattening based on WGS84 a <- 20925646 + #a <- 6378137 f <- 1/298.257223563 e2 <- f*(2-f) - R1 <- a*(1-e2)/(1-e2*(sin(originLatitude))^2)^(3/2) - R2 <- a/sqrt(1-e2*(sin(originLatitude))^2) + R1 <- a*(1-e2)/(1-e2*(sin(lat0))^2)^(3/2) + R2 <- a/sqrt(1-e2*(sin(lat0))^2) - xDistance <- R2 * cos(originLatitude) * dlon - yDistance <- R1 * dlat + xyFeet <- cbind(R2 * cos(lat0) * dlon, + R1 * dlat) - return(cbind(xDistance, yDistance)) + return(xyFeet) } diff --git a/tests/testthat/test_lonlatToXY.R b/tests/testthat/test_lonlatToXY.R @@ -0,0 +1,17 @@ +library(flightconflicts) +context("lonlatToXY") + +test_that("Returns sensible values", { + kacyLon <- -74.5771667 + kacyLat <- 39.4575833 + # Find points 500 feet (152.4 m) from the origin + compassPoints <- geosphere::destPoint(c(kacyLon, kacyLat), + b = seq(0, 359, by = 45), + d = 152.4) + + xyFeet <- lonlatToXY(compassPoints[, 1], compassPoints[, 2], kacyLon, kacyLat) + + expect_equal(xyFeet[1, ], c(0, 500), tolerance = 1e-4) + expect_equal(xyFeet[3, ], c(500, 0), tolerance = 1e-4) + expect_equal(sqrt(apply(xyFeet^2, 1, sum)), rep(500, 8), tolerance = 1e-4) +})