Skip to content
Prev 10945 / 29559 Next

Efficient way to obtain gridded count of overlapping polygons?

Yes, the (relatively) new method "over" does this for you, as in

pts$n = sapply(over(pts, geometry(sppX3), returnList = TRUE), length)

In the context of a running script:

require(sp)
con <- url(
"http://sites.google.com/site/ldemisc/polygon-intersect/spp.shp.Rdata")
load(con)
close(con)
proj4string(pts) = proj4string(sppX3) # otherwise over will fail here;
pts$n = sapply(over(pts, geometry(sppX3), returnList = TRUE), length)
gridded(pts)=TRUE
spplot(pts["n"], sp.layout=list("sp.polygons", sppX3, first=F))
On 02/17/2011 04:58 AM, Lyndon Estes wrote: