[R-sig-Geo] Efficient way to obtain gridded count of overlapping polygons?
Lyndon Estes
lestes at princeton.edu
Thu Feb 17 18:36:24 CET 2011
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 <r.hijmans at gmail.com> 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
> R-sig-Geo at r-project.org
> 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)
lestes at princeton.edu
More information about the R-sig-Geo
mailing list