From cb0e2e56127f6dedd83744e8b515581b373d4abd Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Fri, 3 Sep 2021 19:28:18 +0100 Subject: [PATCH] Improve docs for slope_xyz() This fixes another issue in #20 by mentioning alternative functions that can be passed to the fun argument --- R/slopes.R | 10 ++++++++++ man/slope_raster.Rd | 2 ++ man/slope_xyz.Rd | 11 ++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/R/slopes.R b/R/slopes.R index d781eb5..05dea76 100644 --- a/R/slopes.R +++ b/R/slopes.R @@ -255,6 +255,14 @@ slope_raster = function( #' Extract slopes from xyz data frame or sf objects #' +#' The function takes a sf object with 'XYZ' coordinates and returns a vector +#' of numeric values representing the average slope of each linestring in the +#' sf data frame input. +#' +#' The default function to calculate the mean slope is `slope_matrix_weighted()`. +#' You can also use `slope_matrix_mean()` from the package or any other +#' function that takes the same inputs as these functions not in the package. +#' #' @param route_xyz An sf object with x, y, z dimensions #' @param lonlat Are the coordinates in lon/lat order? TRUE by default #' @inheritParams slope_raster @@ -264,7 +272,9 @@ slope_raster = function( #' @examples #' route_xyz = lisbon_road_segment_3d #' slope_xyz(route_xyz, lonlat = FALSE) +#' slope_xyz(route_xyz$geom, lonlat = FALSE) #' slope_xyz(route_xyz, lonlat = FALSE, directed = TRUE) +#' slope_xyz(route_xyz, lonlat = FALSE, fun = slope_matrix_mean) slope_xyz = function( route_xyz, fun = slope_matrix_weighted, diff --git a/man/slope_raster.Rd b/man/slope_raster.Rd index da90a35..6feff4b 100644 --- a/man/slope_raster.Rd +++ b/man/slope_raster.Rd @@ -62,4 +62,6 @@ routes = lisbon_road_network[1:3, ] dem = dem_lisbon_raster (s = slope_raster(routes, dem)) cor(routes$Avg_Slope, s) +slope_raster(routes, dem, directed = TRUE) +slope_raster(sf::st_reverse(routes), dem, directed = TRUE) } diff --git a/man/slope_xyz.Rd b/man/slope_xyz.Rd index 31327a4..6282d1f 100644 --- a/man/slope_xyz.Rd +++ b/man/slope_xyz.Rd @@ -28,10 +28,19 @@ A vector of slopes equal in length to the number simple features (rows representing linestrings) in the input object. } \description{ -Extract slopes from xyz data frame or sf objects +The function takes a sf object with 'XYZ' coordinates and returns a vector +of numeric values representing the average slope of each linestring in the +sf data frame input. +} +\details{ +The default function to calculate the mean slope is \code{slope_matrix_weighted()}. +You can also use \code{slope_matrix_mean()} from the package or any other +function that takes the same inputs as these functions not in the package. } \examples{ route_xyz = lisbon_road_segment_3d slope_xyz(route_xyz, lonlat = FALSE) +slope_xyz(route_xyz$geom, lonlat = FALSE) slope_xyz(route_xyz, lonlat = FALSE, directed = TRUE) +slope_xyz(route_xyz, lonlat = FALSE, fun = slope_matrix_mean) }