why gIntersection is giving TopologyException if b

2019-08-02 23:34发布

问题:

I'm trying

set97 <- gIntersection(setbp,d97)

and getting the error message:

Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_intersection") : 
  TopologyException: found non-noded intersection between LINESTRING (533036 -314770, 533036 -314770) and LINESTRING (533036 -314780, 533036 -314770) at 533035.88110651996 -314769.97350772272

(setbp is a sector of a county - for census purposes - and d97 is the deforestation in brazilian Amazon up to 1997.) When I do

gIsValid(d97)
gIsValid(setbp)
gIntersects(setbp,d97)

I get TRUE for all three questions. So, what's wrong? I'll try gBuffer with 0 width (it solves some of these issues), but I'd like to understand what's going on.

EDIT: gBuffer didn't work. @mdsumner suggested me to do the gIntersection row by row, but up to now (after trying 3 different methods), it didn't work either (look at the comments). Stranger yet, the TopologyException is being caused by strange "strips" of geometry not detected by gIsValid, and worse yet, kilometers apart from the intersecting polygon (setbp above, setbpi in the comments). I'll try the function shown here, though it doesn't seem a rounding problem.