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_sftrack(data = data.frame(), ...)
# S3 method for data.frame
as_sftrack(
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 sftraj
as_sftrack(data, ...)
# S3 method for ltraj
as_sftrack(data, ...)
# S3 method for sf
as_sftrack(
data,
...,
coords,
group,
active_group = NA,
time,
error = NA,
group_name = "sft_group",
timestamp_name = "sft_timestamp",
error_name = "sft_error",
overwrite_names = FALSE
)
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
a character vector describing where the x,y,z coordinates are located in `data` or a list with x,y,z (optional) vectors
a list of named vectors describing multiple grouping variables or a character vector naming the other grouping columns in `data`.
a character vector of the burst names to be 'active' to group data by for analysis
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
(optional) a vector of error information for the movement dataa character string naming the column in `data` where the error information is located
Coordinate reference system to be assigned; object of class `crs`. Defaults to NA
logical whether to convert 0s in spatial data into NAs. Defaults to FALSE.
(optional) new column name for grouping data
(optional) new column name for time data
(optional) new column name for error data
T/F Whether to overwrite data if a group/time/error column name is supplied but already in data
Convert objects into sftrack objects.
#'
data("raccoon")
raccoon$timestamp <- as.POSIXct(raccoon$timestamp, "EST")
burstz <- list(id = raccoon$animal_id, month = as.POSIXlt(raccoon$timestamp)$mon)
# Input is a data.frame
my_track <- as_sftrack(raccoon,
group = burstz, time = "timestamp",
error = NA, coords = c("longitude", "latitude")
)
# Input is a ltraj
library("adehabitatLT")
#> Loading required package: sp
#> Loading required package: ade4
#> Loading required package: adehabitatMA
#> Loading required package: CircStats
#> Loading required package: MASS
#> Loading required package: boot
ltraj_df <- as.ltraj(
xy = raccoon[, c("longitude", "latitude")],
date = as.POSIXct(raccoon$timestamp),
id = raccoon$animal_id, typeII = TRUE,
infolocs = raccoon[, 1:6]
)
my_sftrack <- as_sftrack(ltraj_df)
head(my_sftrack)
#> Sftrack with 6 features and 12 fields (1 empty geometries)
#> Geometry : "geometry" (XY, crs: NA)
#> Timestamp : "sft_timestamp" (POSIXct in UTC)
#> Groupings : "sft_group" (*id*)
#> -------------------------------
#> x y burst sft_timestamp animal_id latitude longitude
#> 223 NA NA TTP-041 2019-01-19 00:02:30 TTP-041 NA NA
#> 224 -80.27933 26.07096 TTP-041 2019-01-19 01:02:30 TTP-041 26.07096 -80.27933
#> 225 -80.27932 26.07025 TTP-041 2019-01-19 02:02:22 TTP-041 26.07025 -80.27932
#> 226 -80.27936 26.07071 TTP-041 2019-01-19 03:02:13 TTP-041 26.07071 -80.27936
#> 227 -80.27924 26.07097 TTP-041 2019-01-19 04:02:30 TTP-041 26.07097 -80.27924
#> 228 -80.27942 26.07072 TTP-041 2019-01-19 05:02:09 TTP-041 26.07072 -80.27942
#> timestamp height hdop sft_group geometry
#> 223 2019-01-19 00:02:30 NA 0.0 (id: TTP-041) POINT EMPTY
#> 224 2019-01-19 01:02:30 7 7.0 (id: TTP-041) POINT (-80.27933 26.07096)
#> 225 2019-01-19 02:02:22 7 3.9 (id: TTP-041) POINT (-80.27932 26.07025)
#> 226 2019-01-19 03:02:13 1 4.7 (id: TTP-041) POINT (-80.27936 26.07071)
#> 227 2019-01-19 04:02:30 23 4.5 (id: TTP-041) POINT (-80.27924 26.07097)
#> 228 2019-01-19 05:02:09 22 2.3 (id: TTP-041) POINT (-80.27942 26.07072)
# Input is a sf object
library("sf")
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
df1 <- raccoon[!is.na(raccoon$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 with 6 features and 8 fields (0 empty geometries)
#> Geometry : "geometry" (XY, crs: NA)
#> Timestamp : "timestamp" (POSIXct in UTC)
#> Groupings : "sft_group" (*id*)
#> -------------------------------
#> animal_id timestamp height hdop vdop fix sft_group
#> 2 TTP-058 2019-01-19 01:02:30 7 6.2 3.2 2D (id: TTP-058)
#> 5 TTP-058 2019-01-19 04:02:30 858 5.1 3.2 2D (id: TTP-058)
#> 6 TTP-058 2019-01-19 05:02:30 350 1.9 3.2 3D (id: TTP-058)
#> 7 TTP-058 2019-01-19 06:02:30 11 2.3 4.5 3D (id: TTP-058)
#> 8 TTP-058 2019-01-19 07:02:04 9 2.7 3.9 3D (id: TTP-058)
#> 10 TTP-058 2019-01-19 17: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 sftraj object
my_traj <- as_sftraj(raccoon,
time = "timestamp",
error = NA, coords = c("longitude", "latitude"),
group = burstz
)
new_track <- as_sftrack(my_traj)
head(new_track)
#> Sftrack with 6 features and 10 fields (3 empty geometries)
#> Geometry : "geometry" (XY, crs: NA)
#> Timestamp : "timestamp" (POSIXct in UTC)
#> Groupings : "sft_group" (*id*, *month*)
#> -------------------------------
#> animal_id latitude longitude timestamp height hdop vdop fix
#> 1 TTP-058 NA NA 2019-01-19 00:02:30 NA 0.0 0.0 NO
#> 2 TTP-058 26.06945 -80.27906 2019-01-19 01:02:30 7 6.2 3.2 2D
#> 3 TTP-058 NA NA 2019-01-19 02:02:30 NA 0.0 0.0 NO
#> 4 TTP-058 NA NA 2019-01-19 03:02:30 NA 0.0 0.0 NO
#> 5 TTP-058 26.06769 -80.27431 2019-01-19 04:02:30 858 5.1 3.2 2D
#> 6 TTP-058 26.06867 -80.27930 2019-01-19 05:02:30 350 1.9 3.2 3D
#> sft_group geometry
#> 1 (id: TTP-058, month: 0) POINT EMPTY
#> 2 (id: TTP-058, month: 0) POINT (-80.27906 26.06945)
#> 3 (id: TTP-058, month: 0) POINT EMPTY
#> 4 (id: TTP-058, month: 0) POINT EMPTY
#> 5 (id: TTP-058, month: 0) POINT (-80.27431 26.06769)
#> 6 (id: TTP-058, month: 0) POINT (-80.2793 26.06867)
######################
# Builder