【发布时间】:2019-04-03 06:49:00
【问题描述】:
拥有包含多个多边形的形状文件,这些多边形具有区域和地块的逻辑划分。图在区域上重叠。任务是解散/合并带有无重叠区域的地块。
这是形状文件的 spplot。这里的地块位于 Field Zones 的顶部。 这里还有重叠多边形(区域和绘图)的 shapefile:Shapefile
在 QGIS 中,使用提取区域和绘图,找到差异然后使用 Union 溶解来实现相同的目的。现在需要在 R 中进行相同的编程。
在 R 中尝试了以下步骤,但无法获得正确的结果,正在寻找如何在 R 中溶解这种类型的重叠多边形:
library(sp);
library(raster);
library(rgeos)
#Importing the shape files
field_boundary_fp <- "Database/gadenstedt2_outer_field 3 -26_0_zoned-plotm.shp"
poly_map_proj_str <- "+proj=longlat +datum=WGS84 +no_defs";
utm_target_proj <- "+init=epsg:32632";
field_boundary_sdf <- maptools::readShapePoly(fn = field_boundary_fp,
proj4string = CRS(poly_map_proj_str),
repair = T,
delete_null_obj = T,
verbose = T);
spplot(
field_boundary_sdf,"Rx"
)
# Extracting the Zones and Plots#
Zone_sdf <- field_boundary_sdf[field_boundary_sdf@data$Type == "Zone", ]
Plot_sdf <- field_boundary_sdf[field_boundary_sdf@data$Type == "Plot", ]
plot(Plot_sdf)
plot(Zone_sdf)
#Finding the Intersection Part between the both
test <- gIntersection(Zone_sdf, Plot_sdf,id="ZoneIdx")
plot(test)
plot(test, add = T, col = 'blue')
# Finding the difference
test2 <- gDifference(Zone_sdf,Plot_sdf,id="ZoneIdx")
plot(test2)
plot(test2, add = T, col = 'red')
#Trying for Union then
polygon3 <- gUnion(test2, Plot_sdf,id="ZoneIdx")
plot(polygon3)
plot(polygon3, add = T, col = 'yellow')
【问题讨论】:
-
我们没有你的数据,所以我们不能运行你的代码,所以我们看不出哪里出了问题。请更新您的问题。
-
感谢@Spacedman 的回复。已上传包含多边形和相关数据的 shapefile。链接:filedropper.com/shapefile
标签: r r-raster sp rgeo-shapefile