R/slopes.R
elevation_add.Rd
Take a linestring and add a third (z) dimension to its coordinates
elevation_add( routes, dem = NULL, method = "bilinear", terra = has_terra() && methods::is(dem, "SpatRaster") )
routes | Routes, the gradients of which are to be calculated.
The object must be of class |
---|---|
dem | Raster overlapping with |
method | The method of estimating elevation at points,
passed to the |
terra | Should the |
An sf object that is identical to the input routes
, except that
the coordinate values in the ouput has a third z
dimension representing
the elevation of each vertex that defines a linear feature such as a road.
library(sf) routes = lisbon_road_network[204, ] dem = dem_lisbon_raster (r3d = elevation_add(routes, dem))#> Simple feature collection with 1 feature and 7 fields #> Geometry type: LINESTRING #> Dimension: XYZ #> Bounding box: xmin: -87080.48 ymin: -105629.6 xmax: -87056.99 ymax: -105506.3 #> z_range: zmin: 86.49414 zmax: 92.31126 #> Projected CRS: ETRS89 / Portugal TM06 #> # A tibble: 1 × 8 #> OBJECTID Z_Min Z_Max Z_Mean Min_Slope Max_Slope Avg_Slope #> * <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 2997 86.5 92.3 89.9 0.334 32.0 7.49 #> # … with 1 more variable: geom <LINESTRING [m]>#> NULL#> zmin zmax #> 86.49414 92.31126# \donttest{ # Get elevation data (requires internet connection and API key): r3d_get = elevation_add(cyclestreets_route)#>#> Preparing to download: 6 tiles at zoom = 14 from #> https://api.mapbox.com/v4/mapbox.terrain-rgb/#> Error in curl::curl_download(url = api_query, outfile): HTTP error 401.#> Error in st_crs(x): object 'r3d_get' not found# }