── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
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.
Tasks 1: Import and visualize spatial data
Since Feldaufnahmen_Fanel.gpkg is a vector dataset, you can import it using read_sf(). Explore this dataset in R to answer the following questions:
What information does the dataset contain?
What is the geometry type of the dataset (possible types are: Point, Lines and Polygons)? Polygons
What are the data types of the other columns? nummeric, character
What is the coordinate system of the dataset? CH1903+ / LV95
fanel <-read_sf("Feldaufnahmen_Fanel.gpkg")
Task 2: Annotate Trajectories from vector data
We would like to know what crop was visited by which wild boar, and at what time. Since the crop data is most relevant in summer, filter your wild boar data to the months may to june first and save the output to a new variable. Overlay the filtered dataset with your fanel data to verify the spatial overlap.
To sematically annotate each wild boar location with crop information, you can use a spatial join with the function st_join(). Do this and explore your annotated dataset.
To sematically annotate each wild boar location with crop information, you can use a spatial join with the function st_join(). Do this and explore your annotated dataset.
Think of ways you could visually explore the spatio-temporal patterns of wild boar in relation to the crops. In our example below we visualize the percentage of samples in a given crop per hour.
wildschwein_filter <- wildschwein_filter |>mutate(time_rounded =round_date(DatetimeUTC, "hour")) |>mutate(time =hour(time_rounded)) wildschwein_filter$Frucht <-as.character(wildschwein_filter$Frucht)keep <-c("Rueben", "Gerste", "Feuchtgebiet", "Wald")wildschwein_filter$Frucht[!wildschwein_filter$Frucht %in% keep] <-"other"ggplot(wildschwein_filter, aes(x = time, fill = Frucht)) +geom_bar(position ="fill", colour =NA, width =1) +scale_y_continuous(labels = scales::percent) +labs(y ="Percentage", x ="Time (rounded to the nearest hour)") +facet_wrap(~TierName) +theme_bw()
Task 4: Import and visualize vegetationindex (raster data)
In terms of raster data, we have prepared the Vegetation Height Model provided by the Swiss National Forest Inventory (NFI). This dataset contains high resolution information (1x1 Meter) on the vegetation height, which is determined from the difference between the digital surface models DSM and the digital terrain model by swisstopo (swissAlti3D). Buildings are eliminated using a combination of the ground areas of the swisstopo topographic landscape model (TLM) and spectral information from the stereo aerial photos.
Import this dataset using the function rast from the package terra. Visualize the raster data using the base plot function and tmap. We do not recommend using ggplot2 in this case, as is very slow with raster data.
library(terra)
terra 1.9.27
Attache Paket: 'terra'
Das folgende Objekt ist maskiert 'package:tidyr':
extract
SpatRaster object downsampled to 2753 by 3634 cells.
Task 5: Annotate Trajectories from raster data
Semantically annotate your wild boar locations with the vegetation index . Since you are annotating a vector dataset with information from a raster dataset, you cannot use st_join but need the function extract from the terra package. Read the help on the extract function to see what the function expects.
vegetation_extract <-extract(vegetation, wildschwein_filter)# join extracted values back to your point attribute tablewildschwein_filter$vegetationshoehe_LFI <- vegetation_extract[,2]wildschwein_filter |>select(TierID, DatetimeUTC, vegetationshoehe_LFI, geometry) |>head(10)