【问题标题】:raster::erase function - Error in RGEOSBinTopoFunc : TopologyExceptionraster::erase 函数 - RGEOSBinTopoFunc 中的错误:TopologyException
【发布时间】:2020-03-15 22:02:57
【问题描述】:

根据我之前的帖子解决方案,我正在使用光栅包擦除功能来裁剪和溶解重叠的多边形 - Dissolve Overlapping Polygons using difference and union in R

对于某些多边形,我使用擦除功能遇到错误:

RGEOSBinTopoFunc 中的错误(spgeom1,spgeom2,byid,id,drop_lower_td,unaryUnion_if_byid_false,: TopologyException:输入几何 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)

【问题讨论】:

  • 错误信息很清楚。绘制该位置的图。然后修复它...如果您不知道使用,crop 仅选择该区域以便您可以共享数据。
  • 感谢 Robert 的回复...。您可以从这里下载测试 shapefile - filedropper.com/trialmap1
  • @RobertHijmans 你有没有机会研究同样的问题......任何可能的解决方案......
  • 我无权访问该文件。最好不要使用文件,而是将数据作为代码共享(参见例如geom)。但如果这太难了,也许使用谷歌驱动器? Filedropper 对我不起作用 --- 只是广告

标签: r raster r-raster rgeo-shapefile


【解决方案1】:

绘图多边形真的很乱。即使它们是有效的。 erase 中出现的问题变成它聚合(“dissolves”)参数y(“fields”),但会生成无效的拓扑。我需要研究如何最好地捕捉它,但是,现在(也许有一段时间),这里有一个使用 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) 

【讨论】:

  • 感谢您提出解决方法.... 这当然有帮助,因为我需要使用 R 脚本自动执行此功能,因此无法选择工具,也许我会详细介绍 rmapshaper r 包。我计划通过首先将形状文件转换为 GeoJSON 格式来发布另一个与将形状文件转换为 ISO XML 格式相关的问题 - 如果 R Script / R Packages 相关的形状文件可用于将形状文件或 GeoJSON 转换为 ISO,请指导我XML 格式 - agrarheute.com/technik/traktoren/iso-xml-Datei-erklaert-563240
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多