flightconflicts

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

trajectoryToXYZ.R (1096B)


      1 #' Convert trajectories to Easting/Northing representation.
      2 #' 
      3 #' @param trajectory A flighttrajectory object.
      4 #' @param origin A length 2 numeric vector giving the origin lon/lat for the
      5 #'   conversion.
      6 #' @return A flattrajectory object.
      7 trajectoryToXYZ <- function(trajectory, origin) {
      8   if (!flightpathr::is.flighttrajectory(trajectory)) {
      9     stop("'trajectory' must be an instance of flighttrajectory")
     10   }
     11   if (!is.numeric(origin) || length(origin) != 2) {
     12     stop("'origin' must be a numeric vector of length 2")
     13   }
     14   
     15   trajectoryXY <- lonlatToXY(trajectory$longitude, trajectory$latitude, 
     16                              origin[1], origin[2])
     17   
     18   velocityXY <- bearingToXY(trajectory$bearing, trajectory$groundspeed)
     19   
     20   flattrajectory <- list(origin = origin,
     21                          position = cbind(trajectoryXY, trajectory$altitude),
     22                          velocity = velocityXY)
     23   class(flattrajectory) <- "flattrajectory"
     24   
     25   return(flattrajectory)
     26 }
     27 
     28 #' Check if an object is a flighttrajectory
     29 #' @export
     30 is.flattrajectory <- function(x) inherits(x, "flattrajectory")