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.
# Careful! What Timezone is assumed? remove = false = we don't want the other columns to be removed. rosa <- wildschwein |>st_as_sf(coords =c("E", "N"), crs =2056, remove =FALSE) |>filter( TierName =="Rosa", DatetimeUTC >="2014-12-31", DatetimeUTC <"2015-01-29" )ggplot(rosa) +geom_sf()+geom_path(aes(E, N))
Task 1: Calculate distances
a): Specify a temporal window v and Step b): Measure the distance to every point within v, which you had used with sabi, on on your own movement data or to a different wild boar using different sampling intervals.
distance_by_element <-function(later, now) {as.numeric(st_distance(later, now, by_element =TRUE) )}rosa <- rosa |>mutate(nMinus2 =distance_by_element(lag(geometry, 2), geometry), # distance to pos -30 minutesnMinus1 =distance_by_element(lag(geometry, 1), geometry), # distance to pos -15 minutesnPlus1 =distance_by_element(geometry, lead(geometry, 1)), # distance to pos +15 mintuesnPlus2 =distance_by_element(geometry, lead(geometry, 2)) # distance to pos +30 minutes )
Task 2: Specify and apply threshold d
rosa <- rosa |>rowwise() |>mutate(stepMean =mean(c(nMinus2, nMinus1, nPlus1, nPlus2))) |>ungroup()threshold =mean(rosa$stepMean, na.rm =TRUE)rosa <- rosa |>mutate(static = stepMean < threshold)
Task 3: Visualize segmented trajectories
rosa |>ggplot(aes(x = E, y = N, colour = static)) +geom_path() +geom_point() +coord_equal() +theme(legend.position ="bottom")
Task 4: Segment-based analysis
rle_id <-function(vec) { x <-rle(vec)$lengthsas.factor(rep(seq_along(x), times = x))}rosa <- rosa |>mutate(segment_id =rle_id(static)) |>mutate(timestamp =as.POSIXct(DatetimeUTC))rosa_moving <- rosa |>filter(!static)ggplot(rosa_moving) +geom_sf() +geom_path(aes(E, N, color=segment_id))