R package to define track widths by using crossprofiles. It is created for the course “Introduction to Programming with R” and for my HiWi.
The main idea is, that you have digitized (animal)-tracks and a (high resolution) Digital Surface Model (DSM). The animals stamping out the grassland could make the width of the path visible in the DSM. The width is defined as the distance between the steepest points on each side of the path.
You can directly calculate by defaults the width of your tracks. But it is highly recommended to use the other “check”-functions to see if the default parameters work for your type of track or if you need to adjust these and to get an idea of the quality of the digitization. To understand the parameters, please see this section ‘what are these parameters for?’. With these check-functions you can quickly visualize random example spots on your AOI to get an idea of what is going on. You can also export the GeoPackage to have a closer look on it on a GIS software.
# install.packages("devtools")
devtools::install_github("geoniesun/checkRtrack")
# and load it
library(checkRtrack)
The first step would be to load the data - the digitized tracks and the DSM:
#load tracks
tracks <- read_tracks(system.file("geopackage/tracks.gpkg", package = "checkRtrack"))
#> The next step will be easier if you named the output as 'tracks'
#> ('tracks <- read_track(yourpath)'). If you did already, great!
#load dsm
dsm <- read_dsm(system.file("tif/dsm.tif", package = "checkRtrack"))
#> Next step will be easier if you named the output as 'dsm'
#> ('dsm <- read_dsm(yourDSMpath)'). If you did already, great!
For now, it’s always best to start with generating the minimumpoints. (Check the setting of the parameters under the section ‘what are these parameters for?’). You can also export the GeoPackage and work on it in QGIS or similar:
# create a variable 'mini' to have it ready for the visualization later
mini <- checkMin(dsm, tracks, export = FALSE, dist_cross = 1, profile_length = 1, dist_cross_points = 0.05, st_dev = 0.06)
Let’s have a first look on our minimumpoints. As the entire dataset with all points would be too messy for a quick Map, you will always get a random spot on your tracks that you can have a look on. So just run the line as many times as you want, to have a look on different areas:
#creating a random zoom plot of the minimumpoints
checkMap(dsm, tracks, points = mini, export = FALSE, zoom = 3)
Now let’s see for the sides. You can go immediately for both sides with ‘checkSides()’ or look on each one with ‘checkRight()’ or ‘checkLeft()’. For now we go with both:
#generate side extend of the path
sides <- checkSides(dsm, tracks, export = FALSE, dist_cross = 1, profile_length = 1, dist_cross_points = 0.05)
Let’s check again the map:
#plot random map of minimum and side points
checkMap(dsm, tracks, points = mini, morepoints = sides, export = FALSE, zoom = 3)
Render the checkMap-function as many times as you want… each time will be chosen a random spot on your map.
After checking the tracks we can check the width of the tracks. You will get a sf object returned, which is your input tracks-geopackage with an additional width column. To see for possible digitizing errors you can also plot the map.
# finally, calculate the mean track width of each segment
checkWidth(dsm , tracks, export = FALSE, plot = TRUE, dist_cross = 1, profile_length = 1, dist_cross_points = 0.05, st_dev = 0.06)
We have four parameters that we can adjust. They all are related to the cross profiles that are used to determine the widths. Using the check-functions (except the checkWidth) you can look if e.g. your cross profile length is way too small/big. The first three parameters are demonstrated here on this crossprofile example:
With the standarddeviation (st_dev) you can filter the paths (if there is almost no slope, no width will be possible to be calculated with this approach). important: you need to always visualize along with minimumpoints to be able to see the filtered side extent points. Well, the higher the density of your crossprofiles and points, the better the results. The goal in future is, making the results independent of the profile length. For more understanding, here an overview of what is meant by the “points” that we create with the functions.
Digital Surface Model (DSM) used as example: © Antonio Jose Castañeda Gomez and the UAS-team of the University of Würzburg
Geopackage data used as example: © University of Würzburg (digitized by Leonie Sophie Sonntag)
Welcome ascii font: © Glenn Chappell, 1993