flightpathr

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

coerceTrajectory.R (984B)


      1 # Functions to coerce objects into instances of flighttrajectory. Right now
      2 # these are pretty dumb; in the future it would be smart to look for columns
      3 # that look like, e.g., longitude, latitude, and altitude.
      4 
      5 #' Attempt to coerce an object into an instance of \code{flighttrajectory}.
      6 #' @export
      7 as.flighttrajectory <- function(x) UseMethod("as.flighttrajectory", x)
      8 
      9 #' @method as.flighttrajectory flighttrajectory
     10 #' @export
     11 as.flighttrajectory.flighttrajectory <- function(x) {
     12   return(x)
     13 }
     14 
     15 #' @method as.flighttrajectory data.frame
     16 #' @export
     17 as.flighttrajectory.data.frame <- function(x) {
     18   # TODO: Attempt to match columns to arguments
     19   return(do.call(createTrajectory, as.list(unname(x))))
     20 }
     21 
     22 #' @method as.flighttrajectory matrix
     23 #' @export
     24 as.flighttrajectory.matrix <- function(x) {
     25   return(as.flighttrajectory.data.frame(as.data.frame(x)))
     26 }
     27 
     28 as.flighttrajectory.SpatialPoints <- function(x) {
     29   return(as.flighttrajectory.matrix(as.matrix(sp::coordinates(x))))
     30 }