slope_raster | R Documentation |
This function takes an sf
representing routes over geographical space
and a raster dataset representing the terrain as inputs.
It returns the average gradient of each route feature.
slope_raster(
routes,
dem,
lonlat = sf::st_is_longlat(routes),
method = "bilinear",
fun = slope_matrix_weighted,
terra = has_terra() && methods::is(dem, "SpatRaster"),
directed = FALSE
)
routes |
Routes, the gradients of which are to be calculated.
The object must be of class |
dem |
Raster overlapping with |
lonlat |
Are the routes provided in longitude/latitude coordinates?
By default, value is from the CRS of the routes ( |
method |
The method of estimating elevation at points,
passed to the |
fun |
The slope function to calculate per route,
|
terra |
Should the |
directed |
Should the value be directed? |
If calculating slopes associated with OSM data, the results may be better
if the network is first split-up, e.g. using the function
stplanr::rnet_breakup_vertices()
from the
stplanr
package.
Note: The routes
object must have a geometry type of LINESTRING
.
The sf::st_cast()
function can convert from MULTILINESTRING
(and other)
geometries to LINESTRING
s as follows:
r_linestring = sf::st_cast(routes, "LINESTRING")
.
A vector of slopes equal in length to the number simple features (rows representing linestrings) in the input object.
library(sf)
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)
# Demonstrate that reverse routes have the opposite directed slope
slope_raster(st_reverse(routes), dem, directed = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.