0

我根据我之前的帖子解决方案使用光栅包擦除功能来裁剪和溶解重叠多边形 -使用 R 中的差异和联合溶解重叠多边形

对于某些多边形,擦除功能出现以下错误:

RGEOSBinTopoFunc 中的错误(spgeom1,spgeom2,byid,id,drop_lower_td,unaryUnion_if_byid_false,:TopologyException:输入几何 1 无效:在点 1.1197332302192855 或附近的自相交点 1.1197332302192855 47.203098020153668 在 1.1197332302319268 09825.

library(raster)
library(rgeos)
library(sp)

fields <- gBuffer(fields, byid=TRUE, width=0) # Expands the given geometry to include 
the area within the specified width 

zone <- fields[fields$Type == "Zone", ]
plot <- fields[fields$Type == "Plot", ]

d <- erase(zone, plot) #issue here
spplot(d, "Rx")

# I tried using rgeos::gBuffer to avoid RGEOSBinTopology Exception but it did not worked out. Any guidance in this area would be really helpful.

zone <- gBuffer(zone, byid=TRUE, width=0)
plot <- gBuffer(plot, byid=TRUE, width=0)
4

1 回答 1

0

绘图多边形真的很乱。即使它们是有效的。问题出现在erase它聚合(“溶解”)参数y(“字段”)但生成无效拓扑。我需要研究如何最好地捕捉到它,但是,现在(也许有一段时间),这里有一个使用 cleangeo 的解决方法,但您可能想要使用一个工具来清理字段多边形(捕捉顶点) - ——也许用 Rmapshaper?

library(raster)
library(rgeos)

f <- "WUERZ-I-WW _ Plot _TrialMap.shp"
fields = shapefile(f)
zone <- fields[fields$Type == "Zone", ]
plot <- fields[fields$Type == "Plot", ]

aplot <- aggregate(plot)
rgeos::gIsValid(aplot)
#[1] FALSE
#Warning message:
#In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") :
#  Self-intersection at or near point 13.033265979999999 51.190776640000003

library(cleangeo)
cplot <- clgeo_Clean(aplot)
rgeos::gIsValid(cplot)
# TRUE

d <- erase(zone, cplot) 
于 2020-03-20T04:53:01.830 回答