Skip to content

Commit

Permalink
Updates to elevation_extract for #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Sep 3, 2021
1 parent 4476a38 commit b153e6a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
10 changes: 8 additions & 2 deletions R/slopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ slope_distance_weighted = function(d, elevations, directed = FALSE) {
#' Default value: `m[, 3]`, meaning the 'z' coordinate in a matrix of
#' coordinates.
#' @param m Matrix containing coordinates and elevations.
#' The matrix should have three columns: x, y, and z. Typically
#' The matrix should have three columns: x, y, and z, in that order. Typically
#' these correspond to location in the West-East, South-North, and vertical
#' elevation axes respectively.
#' In data with geographic coordinates, Z values are assumed to be in
Expand Down Expand Up @@ -336,13 +336,16 @@ slope_xyz = function(
#' Fourth International Conference on GeoComputation, Fredericksburg,
#' VA, USA. 1999.
#'
#' @param m Matrix containing coordinates and elevations or an sf
#' object representing a linear feature.
#' @inheritParams slope_raster
#' @inheritParams slope_matrix
#' @return A vector of elevation values.
#' @export
#' @examples
#' m = sf::st_coordinates(lisbon_road_network[1, ])
#' dem = dem_lisbon_raster
#' elevation_extract(lisbon_road_network[1, ], dem)
#' m = sf::st_coordinates(lisbon_road_network[1, ])
#' elevation_extract(m, dem)
#' elevation_extract(m, dem, method = "simple")
#' # Test with terra (requires internet connection):
Expand All @@ -363,6 +366,9 @@ elevation_extract = function(
method = "bilinear",
terra = has_terra() && methods::is(dem, "SpatRaster")
) {
if(any(grepl(pattern = "sf", class(m)))) {
m = sf::st_coordinates(m)
}
if(terra) {
res = terra::extract(dem, m[, 1:2], method = method)[[1]]
} else {
Expand Down
12 changes: 4 additions & 8 deletions man/elevation_extract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sequential_dist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/slope_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b153e6a

Please sign in to comment.