coercePath.R (846B)
1 # Functions to coerce objects into instances of flightpath. 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{flightpath}. 6 #' @export 7 as.flightpath <- function(x) UseMethod("as.flightpath", x) 8 9 #' @method as.flightpath flightpath 10 #' @export 11 as.flightpath.flightpath <- function(x) { 12 return(x) 13 } 14 15 #' @method as.flightpath data.frame 16 #' @export 17 as.flightpath.data.frame <- function(x) { 18 return(do.call(createTrajectory, as.list(unname(x)))) 19 } 20 21 #' @method as.flightpath matrix 22 #' @export 23 as.flightpath.matrix <- function(x) { 24 return(as.flightpath.data.frame(as.data.frame(x))) 25 } 26 27 as.flightpath.SpatialPoints <- function(x) { 28 return(as.flightpath.matrix(as.matrix(sp::coordinates(x)))) 29 }