我对R和sf包还是比较陌生的。
我有两组要分析的多面体数据。我的第一组多边形(火灾)包含数百个野火边界。第二个集合(城镇)包含数百个城市区域边界。
对于每个火灾,我想计算到最近城镇的距离(火灾多边形边缘到最近的城镇多边形边缘),并将其作为字段添加到每个火灾中。
到目前为止,我主要使用sf包来处理空间数据。在我的搜索中,我只能找到多边形到点、点到点、线到点等的最小距离方法,但似乎找不到多边形到多边形的示例。如果能帮助我找到正确的方向,我们将不胜感激!谢谢。
发布于 2018-12-21 03:22:55
@TimSalabim感谢您将我带到正确的方向。我能够完成我想要的东西。也许不是最优雅的解决方案,但它奏效了。
# create an index of the nearest feature
index <- st_nearest_feature(x = poly1, y = poly2)
# slice based on the index
poly2 <- poly2 %>% slice(index)
# calculate distance between polygons
poly_dist <- st_distance(x = poly1, y= poly2, by_element = TRUE)
# add the distance calculations to the fire polygons
poly1$distance <- poly_disthttps://stackoverflow.com/questions/53854803
复制相似问题