r - 用R计算多个多边形之间的最小距离
问题描述
我对 R 和 sf 包还是有点陌生...
我有两组要分析的多面数据。我的第一组多边形(火灾)包含数百个野火周界。第二组(城镇)包含数百个城市区域边界。
对于每次火灾,我想计算到最近城镇的距离(火灾多边形边缘到最近城镇多边形边缘),并将其作为一个字段添加到每个火灾中。
到目前为止,我主要使用 sf 包来存储空间数据。在我的搜索中,我只能找到多边形到点、点到点、线到点等的最小距离方法,但似乎找不到多边形到多边形的例子。任何帮助我朝着正确的方向前进将不胜感激!谢谢你。
解决方案
@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_dist
推荐阅读
- node.js - puppeteer page.evaluate() 随机失败:执行上下文被破坏,很可能是因为导航
- ios - 无法在已安装的 Firebase 组件中使用 Carthage 安装 FirebaseAuth
- datetime - 日期/时间未按预期绘制
- css - (Wordpress CSS)如何在 404 页面上隐藏面包屑和额外空间?
- getstream-io - 当一个活动影响多个提要时如何避免重复
- powershell - Powershell复制特殊的公用文件夹,按原样粘贴。视窗 10
- reactjs - 如何在打字稿中制作组件功能
- python - AttributeError:“NoneType”对象没有属性“电子邮件”
- php - 在 Laravel 观察者中使用自定义 for 循环
- azure - 向 wazure 网络农场中的所有服务器发送消息