Sample transects
sample_transects.RdSample transects.
Arguments
- x
A
SpatRastercontaining at least one layer.- y
A
SpatVectorcontaining a polygon or a line that defines the boundary of an area.- interval
(Numeric). Distance between transects.
- keep
(Numeric). The proportion of vertices from the polygon to be retained. The lower the value, the faster the processing, but at the cost of accuracy. For complex polygons (i.e., long, narrow, and winding ones), a value that is too low may cause the centerline to be truncated. Default value is 1.
- smooth
(Numeric). The smoothing factor of the centerline ranging from 0 to 1. The higher the value, the greater the smoothing. Default value is 0.3.
- transect.length
(Numeric). Transect length. By default, this is automatically estimated. If the transect is too short, enter your preferred value.
Value
The result is a list consisting of four objects:
The centerline of the polygon as
SpatVector.Points on the centerline as
SpatVector.Perpendicular transects to the centerline as
SpatVector.The data frame containing cell values for the transects.
Examples
library("terra")
DEM = system.file("DEM.tif", package = "TrailMapper")
DEM = rast(DEM)
boundary = system.file("boundary.gpkg", package = "TrailMapper")
boundary = vect(boundary)
boundary$ID = 1 # this is now required to work
output = sample_transects(DEM, boundary, interval = 2)
str(output)
#> List of 4
#> $ centerline :S4 class 'SpatVector' [package "terra"]
#> $ central_points :S4 class 'SpatVector' [package "terra"]
#> $ transects :S4 class 'SpatVector' [package "terra"]
#> $ transects_points:'data.frame': 253 obs. of 4 variables:
#> ..$ ID : int [1:253] 1 1 1 1 1 1 1 1 1 1 ...
#> ..$ x : num [1:253] 631877 631877 631877 631877 631877 ...
#> ..$ y : num [1:253] 5814234 5814234 5814234 5814234 5814234 ...
#> ..$ DEM: num [1:253] 111 111 111 111 111 ...
# plot centerline
plot(output[[1]], main = "Centerline")
# plot central points
points(output[[2]])
# plot transects
lines(output[[3]])