Skip to content

Problem with gIntersections {rgeos}

3 messages · Ervan Rutishauser, Lyndon Estes, Colin Rundel

#
This issue is occurring because your poly2 object contains a canopy polygon that is also in the poly object, as such when calculating the intersection the resulting geometry contains that canopy polygon as well as the intersection polygon which is not a valid geometry hence the error. You can either remove the offending canopy from poly, or more likely if you are attempting to work with a single set of canopy polygons you can do something like the following to obtain all the canopy intersections:

inter = gIntersects(poly,byid=TRUE)
inter[!lower.tri(inter)] = FALSE

ids = which(inter,arr.ind=TRUE)

results = list()
for(i in 1:nrow(ids))
{
    results[[i]] = gIntersection(poly[ids[i,1],], poly[ids[i,2],])
}

plot(poly)
for(i in 1:length(results))
{
    plot(results[[i]],col='red', add=TRUE)
}

-Colin
On Nov 1, 2013, at 9:23 AM, Ervan Rutishauser <er.rutishauser at gmail.com> wrote: