检查st_intesection是否为true / false Sf包

时间:2018-10-23 16:25:13

标签: r sf

如何使用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))

1 个答案:

答案 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