簡體   English   中英

用R計算多個多邊形之間的最小距離

[英]Calculate minimum distance between multiple polygons with 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM