代码之家  ›  专栏  ›  技术社区  ›  string

raster::erase函数-RGEOSBinTopoFunc:TopologyException中出错

  •  0
  • string  · 技术社区  · 6 年前

    我正在使用光栅包擦除功能,就像我之前发布的剪切和溶解重叠多边形的解决方案一样- Dissolve Overlapping Polygons using difference and union in R

    对于一些多边形,我得到了下面的erase函数错误:

    RGEOSBinTopoFunc中出错(spgeom1、spgeom2、byid、id、drop_lower_td、unaryUnion_如果byid_false,: 地形异常:输入几何1无效:点1.1197332302192855 47.203098020153668处或附近的自交点1.1197332302192855 47.203098020153668

    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)
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   Robert Hijmans    6 年前

    绘图多边形非常混乱。即使它们是有效的。问题出现在 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)