Skip to contents

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.

Usage

slope_xyz(
  route_xyz,
  fun = slope_matrix_weighted,
  lonlat = TRUE,
  directed = FALSE
)

Arguments

route_xyz

An sf or sfc object with XYZ coordinate dimensions

fun

The slope function to calculate per route, slope_matrix_weighted by default.

lonlat

Are the coordinates in lon/lat order? TRUE by default

directed

Should the value be directed? FALSE by default. If TRUE the result will be negative when it represents a downslope (when the end point is lower than the start point).

Value

A vector of slopes equal in length to the number simple features (rows representing linestrings) in the input object.

Details

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.

Examples

route_xyz = lisbon_road_segment_3d
slope_xyz(route_xyz, lonlat = FALSE)
#>          1 
#> 0.09501323 
slope_xyz(route_xyz$geom, lonlat = FALSE)
#>          1 
#> 0.09501323 
slope_xyz(route_xyz, lonlat = FALSE, directed = TRUE)
#>           1 
#> -0.09501323 
slope_xyz(route_xyz, lonlat = FALSE, fun = slope_matrix_mean)
#>          1 
#> 0.09283052