This function takes a series of points located in geographical space and a digital elevation model as inputs and returns a vector of elevation estimates associated with each point. The function takes locations represented as a matrix of XY (or longitude latitude) coordinates and a digital elevation model (DEM) with class raster or terra. It returns a vector of values representing estimates of elevation associated with each of the points.

elevation_extract(
  m,
  dem,
  method = "bilinear",
  terra = has_terra() && methods::is(dem, "SpatRaster")
)

Arguments

m

Matrix containing coordinates and elevations or an sf object representing a linear feature.

dem

Raster overlapping with routes and values representing elevations

method

The method of estimating elevation at points, passed to the extract function for extracting values from raster datasets. Default: "bilinear".

terra

Should the terra package be used? TRUE by default if the package is installed and if dem is of class SpatRast

Value

A vector of elevation values.

Details

By default, the elevations are estimated using bilinear interpolation (method = "bilinear") which calculates point height based on proximity to the centroids of surrounging cells. The value of the method argument is passed to the method argument in raster::extract() or terra::extract() depending on the class of the input raster dataset.

See Kidner et al. (1999) for descriptions of alternative elevation interpolation and extrapolation algorithms.

References

Kidner, David, Mark Dorey, and Derek Smith. "What’s the point? Interpolation and extrapolation with a regular grid DEM." Fourth International Conference on GeoComputation, Fredericksburg, VA, USA. 1999.

Examples

dem = dem_lisbon_raster elevation_extract(lisbon_road_network[1, ], dem)
#> [1] 3.267991 3.266818 3.265715 3.264418 3.263222 3.262339 3.261004 3.262972 #> [9] 3.264940 3.266908 3.268876 3.308304 3.461349 3.467100 3.439341 3.421206 #> [17] 3.403916 3.387750 3.371584 3.356889 3.342193 3.327498 3.312644 3.297117 #> [25] 3.282411 3.267716 3.253020 3.218922 3.210919 3.202916 3.194914 3.176672 #> [33] 3.157027 3.191458 3.316882 3.410792 3.469193 3.487912 3.563260 3.640330 #> [41] 3.717938
m = sf::st_coordinates(lisbon_road_network[1, ]) elevation_extract(m, dem)
#> [1] 3.267991 3.266818 3.265715 3.264418 3.263222 3.262339 3.261004 3.262972 #> [9] 3.264940 3.266908 3.268876 3.308304 3.461349 3.467100 3.439341 3.421206 #> [17] 3.403916 3.387750 3.371584 3.356889 3.342193 3.327498 3.312644 3.297117 #> [25] 3.282411 3.267716 3.253020 3.218922 3.210919 3.202916 3.194914 3.176672 #> [33] 3.157027 3.191458 3.316882 3.410792 3.469193 3.487912 3.563260 3.640330 #> [41] 3.717938
elevation_extract(m, dem, method = "simple")
#> [1] 3.370 3.370 3.382 3.394 3.406 3.419 3.104 3.116 3.128 3.140 3.152 3.233 #> [13] 3.507 3.400 3.389 3.374 3.363 3.352 3.341 3.341 3.330 3.319 3.308 3.296 #> [25] 3.285 3.274 3.263 3.252 3.252 3.241 3.230 3.219 3.208 3.315 3.451 3.451 #> [37] 3.560 3.560 3.543 3.652 3.762
# Test with terra (requires internet connection): # \donttest{ if(slopes:::has_terra()) { u = paste0("https://github.com/ITSLeeds/slopes/", "releases/download/0.0.0/dem_lisbon.tif" ) f = "dem_lisbon.tif" if(!file.exists(f)) download.file(u, f, mode = "wb") et = terra::rast("dem_lisbon.tif") elevation_extract(m, et) file.remove("dem_lisbon.tif") }
#> [1] TRUE
# }