I am using raster package erase function as per my previous post solution for clipping and dissolving overlapping polygons - Dissolve Overlapping Polygons using difference and union in R
For some of the polygons I am getting below error with erase funtion:
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false, : TopologyException: Input geom 1 is invalid: Self-intersection at or near point 1.1197332302192855 47.203098020153668 at 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)