as_sftrack {sftrack} | R Documentation |
Convert objects into sftrack objects.
Description
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
Usage
as_sftrack(data = data.frame(), ...)
## S3 method for class '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 class 'sftraj'
as_sftrack(data, ...)
## S3 method for class 'ltraj'
as_sftrack(data, ...)
## S3 method for class '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
)
Arguments
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 dataa character string naming the column in 'data' where the error information is located |
crs |
Coordinate reference system to be assigned; object of class 'crs'. 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 |
Details
Convert objects into sftrack objects.
Examples
#'
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")
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)
# Input is a sf object
library("sf")
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)
# 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)
######################
# Builder