# Efficient way to obtain gridded count of overlapping polygons?

5 messages
Open this post in threaded view
|

## Efficient way to obtain gridded count of overlapping polygons?

Open this post in threaded view
|

## Re: Efficient way to obtain gridded count of overlapping polygons?

Open this post in threaded view
|

## Re: Efficient way to obtain gridded count of overlapping polygons?

Open this post in threaded view
|

## Re: Efficient way to obtain gridded count of overlapping polygons?

 In reply to this post by Lyndon Estes > I am interested in creating a raster that summarizes the number of > overlapping polygons that underlie each cell (in order to display how > many species occur at that point). Lyndon, You can also do the below, with raster, see ?rasterize: r <- rasterize(pols, r, fun='count') or r <- rasterize(pols, r, fun=function(x,...)length(na.omit(x)))
Open this post in threaded view
|

## Re: Efficient way to obtain gridded count of overlapping polygons?

 Hi Robert, Many thanks for that suggestion as well, I appreciate it, which also does the trick. Just to update the time differences between the 3 methods, in case anyone else is interested: Function I wrote: 2.07 seconds The "over" method from Edzer: 0.612 seconds Rasterize function: 5.61 seconds (line of code used is below) r2 <- rasterize(sppX3, r, fun = "count") r was created from a shape of Africa with 1 degree resolution Thanks again, Lyndon On Thu, Feb 17, 2011 at 11:48 AM, Robert Hijmans <[hidden email]> wrote: > >> I am interested in creating a raster that summarizes the number of >> overlapping polygons that underlie each cell (in order to display how >> many species occur at that point). > > Lyndon, > > You can also do the below, with raster, see ?rasterize: > > r <- rasterize(pols, r, fun='count') > > or > > r <- rasterize(pols, r, fun=function(x,...)length(na.omit(x))) > > > -- > View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Efficient-way-to-obtain-gridded-count-of-overlapping-polygons-tp6034590p6036670.html> Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > [hidden email] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo> -- Lyndon Estes Research Associate Woodrow Wilson School Princeton University +1-609-258-2392 (o) +1-609-258-6082 (f) +1-202-431-0496 (m) [hidden email] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo