![](/img/trans.png)
[英]R How do I merge polygon features in a shapefile with many polygons? (reproducible code example)
[英]How to merge features contained in a shapefile based on a condition in R
我附上了一個帶有 4 個特征的 shapefile( sample
),每個特征在字段type
都有gap
、 out
、 in
(請參閱屬性表)。 我想將特征gap
特征與具有最大面積的相鄰多邊形合並(在這種情況下, gap
將與in
合並)。 我的最終 shapefile 將具有 3 個特征(沒有gap
)。 我如何在 R 中做到這一點?
在 ArcGIS 中,有一個用於合並要素的直接工具。 我想知道我們如何在 R 中做到這一點。
我已經使用rgeos
庫來找出具有最大面積的相鄰多邊形。 這是我的代碼。 我不知道如何將此功能與gap
功能合並。
library(rgeos)
adj_mat <- gTouches(shp, byid=TRUE)
a <- adj_mat[which(shp@data$type=="gap"),]
area <- shp@data$SHAPE_Area[which(a=="TRUE")]
final_matching_id <- which(area==max(area))
f_gap <- shp@data[final_matching_id+1,]
f_gap
OBJECTID SHAPE_Leng SHAPE_Area type
3 13 1.527046 0.09469124 in
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.