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, ..., fill_missing = FALSE) # 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 )
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 |
fill_missing | T/F When converting from sftraj, new lines may be added to the data.frame if t2 times are missing. Should the columns be filled in with information from t1? |
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_sftrack(raccoons, group = group, time = "timestamp", error = NA, coords = c("longitude", "latitude") ) # 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 sftraj object my_traj <- as_sftraj(raccoons, time = "timestamp", error = NA, coords = c("longitude", "latitude"), group = group ) new_track <- as_sftrack(my_traj) head(new_track)#> sftrack (*locations*) with 6 features and 10 fields #> geometry: "geometry" (XY, CRS: NA) #> timestamps: "timestamp" (integer) #> groupings: "sft_group" (*id*, *month*) #> ------------------------------- #> animal_id latitude longitude timestamp height hdop vdop fix #> 1 TTP-058 NA NA 2019-01-18 19:02:30 NA 0.0 0.0 NO #> 2 TTP-058 26.06945 -80.27906 2019-01-18 20:02:30 7 6.2 3.2 2D #> 3 TTP-058 NA NA 2019-01-18 21:02:30 NA 0.0 0.0 NO #> 4 TTP-058 NA NA 2019-01-18 22:02:30 NA 0.0 0.0 NO #> 5 TTP-058 26.06769 -80.27431 2019-01-18 23:02:30 858 5.1 3.2 2D #> 6 TTP-058 26.06867 -80.27930 2019-01-19 00:02:30 350 1.9 3.2 3D #> sft_group geometry #> 1 (id: TTP-058, month: 1) POINT EMPTY #> 2 (id: TTP-058, month: 1) POINT (-80.27906 26.06945) #> 3 (id: TTP-058, month: 1) POINT EMPTY #> 4 (id: TTP-058, month: 1) POINT EMPTY #> 5 (id: TTP-058, month: 1) POINT (-80.27431 26.06769) #> 6 (id: TTP-058, month: 1) POINT (-80.2793 26.06867)###################### # Builder