是否有等效的sp::over()
in package terra
?要获取显示 SpatVector 的哪些几何图形覆盖另一个 SpatVector 的哪些几何图形的数据框 - 像这样,但仅使用terra
:
# get a polygons map:
library(terra)
lux <- vect(system.file("ex/lux.shp", package="terra"))
plot(lux)
text(lux, lux$NAME_2)
# get points that overlay some of those polygons:
pts <- vect(cbind(c(5.8, 6, 6.2), c(49.85, 49.5, 49.6)), crs = crs(lux))
plot(pts, col = "blue", add = TRUE)
# find which points overlay which polygons:
library(sp); library(raster)
over(as(pts, "Spatial"), as(lux, "Spatial"))
# ID_1 NAME_1 ID_2 NAME_2 AREA POP
# 1 1 Diekirch 3 Redange 259 18664
# 2 3 Luxembourg 9 Esch-sur-Alzette 251 176820
# 3 3 Luxembourg 10 Luxembourg 237 182607