I downloaded two shapefiles from IUCN (available here and here) to determine the range overlap between two species. When I bring the shapefiles into R, I am able to plot them on a map together, however, when I try to calculate percent overlap, I get this error:
p <- readOGR(getwd(), layer="species_7928") w <- readOGR(getwd(), layer="species_21314") EPFU<- gArea(SpatialPolygons(p@polygons)) intersected.area.tabr <- gArea(gIntersection(SpatialPolygons(w@polygons), SpatialPolygons(p@polygons))) (intersected.area.tabr/EPFU)*100 Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id,drop_lower_td, unaryUnion_if_byid_false, : TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point -82.517899999999997 8.2930355900000006 at -82.517899999999997 8.2930355900000006
I've tried the suggested workarounds with
gUnaryUnion, but these also return errors.
I was also able to take a separate map provided by a friend from a different project and each of these files individually worked when I tried to calculate the intersection. I can open these files together in ArcMap. I've run the check geometry tool there and the output table was empty. Is this occurring because there are multiple elements (discontinuous portions of the map)? I do not necessarily have to do this in R, if there is a straightforward way to do the same in ArcMap, but this is my first experience with any sort of GIS data.