Interpolate elevations from points along a centerline
calc_centerline_interpolation.RdInterpolate elevations from points along a centerline
Usage
calc_centerline_interpolation(
points_on_line,
dem,
algorithm = "invdist:power=1",
gdal_options = NULL,
quiet = TRUE
)Arguments
- points_on_line
The output from
points_along_line(): an sfc object of points along the centerline, which will be used as data points for interpolation.- dem
Either a SpatRaster (created via
terra::rast()) or an object thatterra::rast()can read to create a SpatRaster.- algorithm
A string to control the interpolation algorithm. See the gdal_grid documentation at https://gdal.org/programs/gdal_grid.html for the available algorithms and customization options.
- gdal_options
Optionally, a vector of options to pass to
gdal_gridviasf::gdal_utils(). See the full list of options online at https://gdal.org/programs/gdal_grid.html. See Details.- quiet
Boolean: should execution proceed "quietly", without messages (
TRUE) or should progress updates be posted during centerline download and interpolation (FALSE)?
Value
A SpatRaster object (as created by terra::rast()), representing the
outputs of the interpolation process.
Details
The bulk of the processing time for this function involves calling
gdal_grid via sf::gdal_utils(). The results from this function call are
then written out as a TIFF file before being read back into the R session.
You can choose to pass options to gdal_grid. However, passing any of
-a, -txe, -tye, -tr, -outsize, and zfield will cause an error.
Possible options to speed up processing include passing
c("-co", "NUM_THREADS=ALL_CPUS") in order to write the TIFF using multiple
threads, or c("--config" "GDAL_CACHEMAX", "30%") (or another value) to
increase cache utilization above the default 5%.
Examples
if (FALSE) { # rlang::is_interactive()
dem <- system.file("elevation.tiff", package = "rrrem")
centerline <- get_river_centerline(dem)
center_points <- points_along_line(centerline, n_points = n_points)
interpolated_raster <- calc_centerline_interpolation(
center_points,
dem,
quiet = quiet
)
}