2

I'm trying to make a buffer around each polygon in my data. At some point I get:

Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false, : TopologyException: Input geom 1 is invalid: Ring Self-intersection at or near point

I tried to repair the shapefile with

land1 <- gBuffer(land1, byid=TRUE, width=0)

but didn't work.

How can I find the polygons that are problematic? I tried which(!gIsValid(land1, byid=TRUE)) but didn't get the right answer.

  • Welcome to GIS SE. As a new user please take the Tour. Please edit this question to include details about the data, and the steps you have taken to assure that it is topologically clean – Vince Jan 9 '17 at 12:12
1

I've got a draft solution for this problem but it relies on a dev package only available on Github (rangl).

A recent use of it is here: https://github.com/mtennekes/tmap/issues/96#issuecomment-271091194

The key is to triangulate the polygon (with constraints imposed by the polygon boundary on the mesh) and then find ambiguous regions by point-in-poly tests on the triangle centroids. The ambiguous regions are inside overlaps where the rings wind in an invalid way. The approach is described here, but the implementation is all work in progress etc.

https://github.com/r-gris/toposhop/issues/2#issuecomment-264831912

I don't know any other way in R, though rmapshaper and/or polyclip might work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.