我有一个关于某个城市街道的矢量类型空间数据文件,和另一个包含地形坡度的栅格类型空间数据文件。
我的目标是将这两个数据交叉,找出哪些路段最陡峭。
如果这两个数据都是sf类型的数据,我会使用st_intersection函数。但是当这些数据类型不同时,该如何处理?
我的最终目标是生成带有一列标示该路段坡度的矢量形式的空间数据。
可重现的例子:
我的目标是将这两个数据交叉,找出哪些路段最陡峭。
如果这两个数据都是sf类型的数据,我会使用st_intersection函数。但是当这些数据类型不同时,该如何处理?
我的最终目标是生成带有一列标示该路段坡度的矢量形式的空间数据。
可重现的例子:
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.