[R-sig-Geo] poly.counts() very slow: potential alternative suggested
Agustin Lobo
alobolistas at gmail.com
Sat Jan 12 22:36:48 CET 2013
I've found poly.counts() (in GISTools) to be very slow and actually
cannot use it for 2 complex layers (13969 points and 32036 polygons):
system.time(nbp2 <- poly.counts(fireLCg,BorneoLCg))
Error: cannot allocate vector of size 1.7 Gb
Timing stopped at: 351.766 5.164 722.586
while a function based on over() works reasonably well:
system.time(nbp <- minbpINpoly(fireLCg,BorneoLCg))
user system elapsed
46.999 2.088 73.805
Is perhaps my function less general and/or do you appreciate
any other potential problem? Or perhaps there is another alternative
in another package already.
function(points,polys)
{
#Agustin.Lobo at ictja.csic.es
#points:Spatial Points DF
#polys: Spatial Polygons DF
#output:vector
#In order to count the number of fire pixels we first extract the
coordinates to a dumy object
#in which each component corresponds to a polygon and contains a
dataframe with the information
#of each point within that polygon.
#Once we have created such a list, we just count the number of rows of
the data frame within each component.
delme6 <- over(points,polys, returnList = TRUE)
nbp <- sapply(delme6,nrow)
nbp
}
Thanks
Agus
More information about the R-sig-Geo
mailing list