convert to and from ltraj

#' @name as #' @rdname coerce-methods #' @aliases coerce,sftrack #' @export setOldClass('ltraj') setAs("sftrack", "ltraj",function(from) sftrack_to_ltraj(from))

#' @name as #' @rdname coerce-methods #' @aliases coerce,sftracj #' @export setAs("sftraj", "ltraj",function(from) sftraj_to_ltraj(from))

# S3 method for ltraj
as_sftrack(data, ...)

# S3 method for ltraj
as_sftraj(data, ...)

sftrack_to_ltraj(data)

sftraj_to_ltraj(data)

Arguments

data

the data either sftrack,sftraj,or ltraj class to convert

...

ignored

Examples

#' ### Ltraj Methods # Input is a ltraj library(adehabitatLT) ltraj_df <- as.ltraj( xy = raccoons[, c("longitude", "latitude")], date = raccoons$timestamp, id = raccoons$animal_id, typeII = TRUE, infolocs = raccoons[, 1:6] ) my_sftrack <- as_sftrack(ltraj_df) head(my_sftrack)
#> sftrack (*locations*) with 6 features and 12 fields #> geometry: "geometry" (XY, CRS: NA) #> timestamps: "sft_timestamp" (integer) #> groupings: "sft_group" (*id*) #> ------------------------------- #> x y burst sft_timestamp animal_id latitude longitude #> 223 NA NA TTP-041 2019-01-18 19:02:30 TTP-041 NA NA #> 224 -80.27933 26.07096 TTP-041 2019-01-18 20:02:30 TTP-041 26.07096 -80.27933 #> 225 -80.27932 26.07025 TTP-041 2019-01-18 21:02:22 TTP-041 26.07025 -80.27932 #> 226 -80.27936 26.07071 TTP-041 2019-01-18 22:02:13 TTP-041 26.07071 -80.27936 #> 227 -80.27924 26.07097 TTP-041 2019-01-18 23:02:30 TTP-041 26.07097 -80.27924 #> 228 -80.27942 26.07072 TTP-041 2019-01-19 00:02:09 TTP-041 26.07072 -80.27942 #> timestamp height hdop sft_group geometry #> 223 2019-01-18 19:02:30 NA 0.0 (id: TTP-041) POINT EMPTY #> 224 2019-01-18 20:02:30 7 7.0 (id: TTP-041) POINT (-80.27933 26.07096) #> 225 2019-01-18 21:02:22 7 3.9 (id: TTP-041) POINT (-80.27932 26.07025) #> 226 2019-01-18 22:02:13 1 4.7 (id: TTP-041) POINT (-80.27936 26.07071) #> 227 2019-01-18 23:02:30 23 4.5 (id: TTP-041) POINT (-80.27924 26.07097) #> 228 2019-01-19 00:02:09 22 2.3 (id: TTP-041) POINT (-80.27942 26.07072)
my_sftraj <- as_sftraj(ltraj_df) head(my_sftraj)
#> sftraj (*steps*) with 6 features and 12 fields #> geometry: "geometry" (XY, CRS: NA) #> timestamps: "sft_timestamp" (integer) #> groupings: "sft_group" (*id*) #> ------------------------------- #> x y burst sft_timestamp #> 223 NA NA TTP-041 (2019-01-18 19:02:30 --> 2019-01-18 20:02:30) #> 224 -80.27933 26.07096 TTP-041 (2019-01-18 20:02:30 --> 2019-01-18 21:02:22) #> 225 -80.27932 26.07025 TTP-041 (2019-01-18 21:02:22 --> 2019-01-18 22:02:13) #> 226 -80.27936 26.07071 TTP-041 (2019-01-18 22:02:13 --> 2019-01-18 23:02:30) #> 227 -80.27924 26.07097 TTP-041 (2019-01-18 23:02:30 --> 2019-01-19 00:02:09) #> 228 -80.27942 26.07072 TTP-041 (2019-01-19 00:02:09 --> 2019-01-19 01:02:30) #> animal_id latitude longitude timestamp height hdop sft_group #> 223 TTP-041 NA NA 2019-01-18 19:02:30 NA 0.0 (id: TTP-041) #> 224 TTP-041 26.07096 -80.27933 2019-01-18 20:02:30 7 7.0 (id: TTP-041) #> 225 TTP-041 26.07025 -80.27932 2019-01-18 21:02:22 7 3.9 (id: TTP-041) #> 226 TTP-041 26.07071 -80.27936 2019-01-18 22:02:13 1 4.7 (id: TTP-041) #> 227 TTP-041 26.07097 -80.27924 2019-01-18 23:02:30 23 4.5 (id: TTP-041) #> 228 TTP-041 26.07072 -80.27942 2019-01-19 00:02:09 22 2.3 (id: TTP-041) #> geometry #> 223 POINT EMPTY #> 224 LINESTRING (-80.27933 26.07... #> 225 LINESTRING (-80.27932 26.07... #> 226 LINESTRING (-80.27936 26.07... #> 227 LINESTRING (-80.27924 26.07... #> 228 LINESTRING (-80.27942 26.07...
# convert back sftrack_to_ltraj(my_sftrack)
#> #> *********** List of class ltraj *********** #> #> Type of the traject: Type II (time recorded) #> * Time zone: EST5EDT * #> Irregular traject. Variable time lag between two locs #> #> Characteristics of the bursts: #> id burst nb.reloc NAs date.begin date.end #> 1 TTP-041 TTP-041 223 101 2019-01-18 19:02:30 2019-02-01 18:02:07 #> 2 TTP-058 TTP-058 222 67 2019-01-18 19:02:30 2019-02-01 18:02:30 #> #> #> infolocs provided. The following variables are available: #> [1] "x" "y" "burst" "animal_id" "latitude" "longitude" #> [7] "timestamp" "height" "hdop"
sftraj_to_ltraj(my_sftraj)
#> #> *********** List of class ltraj *********** #> #> Type of the traject: Type II (time recorded) #> * Time zone: EST5EDT * #> Irregular traject. Variable time lag between two locs #> #> Characteristics of the bursts: #> id burst nb.reloc NAs date.begin date.end #> 1 TTP-041 TTP-041 223 101 2019-01-18 19:02:30 2019-02-01 18:02:07 #> 2 TTP-058 TTP-058 222 67 2019-01-18 19:02:30 2019-02-01 18:02:30 #> #> #> infolocs provided. The following variables are available: #> [1] "x" "y" "burst" "animal_id" "latitude" "longitude" #> [7] "timestamp" "height" "hdop"