This function converts x,y,z data into an sftrack object with a sf_geometry column of sf_POINTS. Creates a `grouping` column to group movement data and sets dedicated time and error columns.
Raw data inputted in two ways: vector or data.frame. 'Vector' inputs gives the argument as a vector where length = nrow(data). 'Data.frame' inputs gives the arguments as the column name of `data` where the input can be found. Either input is allowed on any given argument.
Some options are global and required regardless
as_sftraj(data = data.frame(), ...) # S3 method for data.frame as_sftraj( data = data.frame(), ..., coords = c("x", "y"), group = "id", active_group = NA, time = "time", error = NA, crs = NA, zeroNA = FALSE, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE ) # S3 method for sftrack as_sftraj(data, ...) # S3 method for sf as_sftraj( data, ..., coords, group, active_group = NA, time, error = NA, group_name = "sft_group", timestamp_name = "sft_timestamp", error_name = "sft_error", overwrite_names = FALSE )
data | a data.frame of the movement data, if supplied all data.frame inputs, than is optional |
---|---|
... | extra information to be passed on to as_sftrack |
coords | a character vector describing where the x,y,z coordinates are located in `data` or a list with x,y,z (optional) vectors |
group | a list of named vectors describing multiple grouping variables or a character vector naming the other grouping columns in `data`. |
active_group | a character vector of the burst names to be 'active' to group data by for analysis |
time | a vector of time information, can be either POSIX or an integer or a character string naming the column in `data` where the time information is located |
error | (optional) a vector of error information for the movement data, or a character string naming the column in `data` where the error information is located |
crs | a crs string from rgdal of the crs and projection information for the spatial data. Defaults to NA |
zeroNA | logical whether to convert 0s in spatial data into NAs. Defaults to FALSE. |
group_name | (optional) new column name for grouping data |
timestamp_name | (optional) new column name for time data |
error_name | (optional) new column name for error data |
overwrite_names | T/F Whether to overwrite data if a group/time/error column name is supplied but already in data |
Convert objects into sftrack objects.
#' group <- list(id = raccoons$animal_id, month = as.POSIXlt(raccoons$timestamp)$mon+1) # Input is a data.frame my_track <- as_sftraj(raccoons, group = group, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) # 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_sftraj(ltraj_df) head(my_sftrack)#> 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...# Input is a sf object library("sf") df1 <- raccoons[!is.na(raccoons$latitude), ] sf_df <- st_as_sf(df1, coords = c("longitude", "latitude")) new_sftrack <- as_sftrack(sf_df, group = c(id = "animal_id"), time = "timestamp") head(new_sftrack)#> sftrack (*locations*) with 6 features and 8 fields #> geometry: "geometry" (XY, CRS: NA) #> timestamps: "timestamp" (integer) #> groupings: "sft_group" (*id*) #> ------------------------------- #> animal_id timestamp height hdop vdop fix sft_group #> 2 TTP-058 2019-01-18 20:02:30 7 6.2 3.2 2D (id: TTP-058) #> 5 TTP-058 2019-01-18 23:02:30 858 5.1 3.2 2D (id: TTP-058) #> 6 TTP-058 2019-01-19 00:02:30 350 1.9 3.2 3D (id: TTP-058) #> 7 TTP-058 2019-01-19 01:02:30 11 2.3 4.5 3D (id: TTP-058) #> 8 TTP-058 2019-01-19 02:02:04 9 2.7 3.9 3D (id: TTP-058) #> 10 TTP-058 2019-01-19 12:02:30 NA 2.0 3.3 3D (id: TTP-058) #> geometry #> 2 POINT (-80.27906 26.06945) #> 5 POINT (-80.27431 26.06769) #> 6 POINT (-80.2793 26.06867) #> 7 POINT (-80.27908 26.06962) #> 8 POINT (-80.27902 26.06963) #> 10 POINT (-80.279 26.06982)# Input is an sftrack object my_track <- as_sftrack(raccoons, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = group ) new_traj <- as_sftraj(my_track) head(new_traj)#> sftraj (*steps*) with 6 features and 10 fields #> geometry: "geometry" (XY, CRS: NA) #> timestamps: "timestamp" (integer) #> groupings: "sft_group" (*id*, *month*) #> ------------------------------- #> animal_id latitude longitude timestamp #> 1 TTP-058 NA NA (2019-01-18 19:02:30 --> 2019-01-18 20:02:30) #> 2 TTP-058 26.06945 -80.27906 (2019-01-18 20:02:30 --> 2019-01-18 21:02:30) #> 3 TTP-058 NA NA (2019-01-18 21:02:30 --> 2019-01-18 22:02:30) #> 4 TTP-058 NA NA (2019-01-18 22:02:30 --> 2019-01-18 23:02:30) #> 5 TTP-058 26.06769 -80.27431 (2019-01-18 23:02:30 --> 2019-01-19 00:02:30) #> 6 TTP-058 26.06867 -80.27930 (2019-01-19 00:02:30 --> 2019-01-19 01:02:30) #> height hdop vdop fix sft_group geometry #> 1 NA 0.0 0.0 NO (id: TTP-058, month: 1) POINT EMPTY #> 2 7 6.2 3.2 2D (id: TTP-058, month: 1) POINT (-80.27906 26.06945) #> 3 NA 0.0 0.0 NO (id: TTP-058, month: 1) POINT EMPTY #> 4 NA 0.0 0.0 NO (id: TTP-058, month: 1) POINT EMPTY #> 5 858 5.1 3.2 2D (id: TTP-058, month: 1) LINESTRING (-80.27431 26.06... #> 6 350 1.9 3.2 3D (id: TTP-058, month: 1) LINESTRING (-80.2793 26.068...######################