我有一个关于给定市政当局街道的vector-type spatial data文件,另一个文件是关于地形坡度的raster-type spatial data文件.
我的目标是交叉这两个数据,找出哪些路段的街道最陡峭.
如果这两个数据都是sf类型的数据,我会使用st_cross函数.但当数据类型不同时,该如何继续呢?
我的最终目标是生成矢量形式的空间数据,并用一列表示该拉伸的坡度.
Reproducible example:个
library(elevatr)
library(terra)
library(geobr)
library(osmdata) # package for working with streets
# 2 - get the municipality shapefile (vectorized spatial data)
municipality_shape <- read_municipality(code_muni = 3305802)
# 3 - get the raster topographical data
t <- elevatr::get_elev_raster(locations = municipality_shape,
z = 10, prj = "EPSG:4674")
obj_raster <- rast(t)
# 4 - calculate the slope
aspect <- terrain(obj_raster, "aspect", unit = "radians")
slope <- terrain(obj_raster, "slope", unit = "radians")
hillshade <- shade(slope, aspect)
# 5 - get the streets data
getbb("Teresópolis")
big_streets <- getbb("Teresópolis") |>
opq() |> # função que faz a query no OSM
add_osm_feature(key = "highway", # selecionar apenas ruas
value = "primary") |> # característica das ruas
osmdata_sf() # retorna a query como um objeto sf
# 6 - intersects the raster hillshade object with the sf object from streets available in big_streets$osm_lines$geometry.