如何使用R中的sf包检查点是否与具有布尔结果的多边形相交
library(sf)
dub<- st_as_sf(data.frame(lon=72.917,lat=19.112), coords=c("lon","lat"),crs=4326)
a<- st_as_sf(data.frame(lon=72.930,lat=19.112), coords=c("lon","lat"), crs=4326)
buf<- st_buffer(a,0.01)
我尝试过交叉点长度,但是不起作用
length(st_intersection(dub,buf))
答案 0 :(得分:1)
使用st_intersects
而不是st_intersection
并设置sparse = FALSE
> st_intersects(dub, buf, sparse = FALSE)
# although coordinates are longitude/latitude, st_intersects assumes
# that they are planar
# [,1]
# [1,] FALSE