R solution for 'TopologyException: Input geom 1 is invalid' self-intersection error?

المشرف العام

Administrator
طاقم الإدارة
The 'TopologyException: Input geom 1 is invalid' self-intersection error which arises from invalid polygon geometries has been widely discussed. However, I haven't found a convenient solution on the web that solely relies on R functionality.

For instance, I have managed to create a 'SpatialPolygonsDataFrame' from the output of ggplot2::map_data("state"), which can be downloaded from here for replication purposes.



The problem is now that self-intersection seemingly occurs at the point given below.

rgeos::gIsValid(spydf_states)[1] FALSEWarning message:In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Self-intersection at or near point -122.22023214285259 38.060546477866055Unfortunatelly, this problem prevents any further use of 'spydf_states', e.g. when calling rgeos::gIntersection. Any help on how to solve this issue from within R would be highly appreciated.



أكثر...
 
أعلى