Rows: 51246 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): TierID, TierName
dbl (3): CollarID, E, N
dttm (1): DatetimeUTC
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(sf)
Linking to GEOS 3.12.2, GDAL 3.11.4, PROJ 9.4.1; sf_use_s2() is TRUE
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
# only get the data from sabi between 1 and 3 of July 2015sabi <-filter(wildschwein_sf, TierName =="Sabi", DatetimeUTC >"2015-07-01", DatetimeUTC <"2015-07-03")# visualize the resultlibrary(ggplot2)ggplot(sabi) +geom_sf() +geom_path(aes(E, N))
Step a): Specify a temporal window v
v is 60 minutes, our sampling interval is 15 minutes. So we need to calculate the following distances:
pos[n-2] to pos[n]
pos[n-1] to pos[n]
pos[n] to pos[n+1]
pos[n] to pos[n+2]
distance_by_element <-function(later, now) {as.numeric(st_distance(later, now, by_element =TRUE) )}sabi <- sabi |>mutate(nMinus2 =distance_by_element(lag(geometry, n =2), geometry),nMinus1 =distance_by_element(lag(geometry, n =1), geometry),nPlus1 =distance_by_element(lead(geometry, n =1), geometry),nPlus2 =distance_by_element(lead(geometry, n =2), geometry) )sabi <- sabi |>rowwise() |>mutate(stepMean =mean(c(nMinus2, nMinus1, nPlus1, nPlus2), na.rm =FALSE) ) |>ungroup()sabi
# fist, specify a threshold. For a simple approach, we'll use the "mean" value as a threshold value# to differentiate between stops and movesthreshold <-mean(sabi$stepMean, na.rm =TRUE)sabi <- sabi |>mutate(static = stepMean < threshold )ggplot(sabi) +geom_path(aes(E, N)) +geom_sf(aes(color = static))