我希望使用R中的sf包,在一个简单的特征数据框中找到离另一个简单的特征数据框中一组点最近的多边形。我一直在使用'st_join'语句中的'st_is_within_distance',但它返回给定距离内的所有内容,而不是最接近的要素。
以前我用'rgeos'包中的'gDistance'和'sp'要素做过这件事:
m = gDistance(a, b, byid = TRUE)
row = apply(m, 2, function(x) which(x == min(x)))
labels = unlist(b@data[row, ]$NAME)
a$NAME <- labels
我想将使用rgeos和sp查找一组点的最近要素的方法转换为使用sf。任何建议或建议都将非常感激。
which.min(st_distance(point, polygons))
? - Calum Youst_nearest_feature
在这里可能会派上用场?https://r-spatial.github.io/sf/reference/st_nearest_feature.html - radek