Skip to content
Prev 14669 / 29559 Next

focal() questions

Robert and r-sig-geo'ers:

When working with raster's focal() function, I had a few questions:

1) How do I send non-spatial parameters to the function (e.g. similar
to the mapply "MoreArgs" parameter)?
2) Is it possible to have a non-raster return from the focal function?
 For instance: I'm trying to code up a local maxima function that
returns the x,y position of all local maxima in an image (I want a
vector of these positions).  I can do this in two steps by first
creating a raster of local maxima (e.g. placing "0" where a pixel is
not a local maxima), and then running through this raster and pull out
all pixels that are not 0.  This, however, has to read two rasters and
write one.  If I could identify a pixel as a local maxima within a
focal() function, and have it return the value as either a
SpatialPoints object or just an x,y coordinate, this would require
reading the image only once, and only writing where there are maxima.
Thoughts?
3) Can focal() be used with a rasterStack or rasterBrick, where the
filter and function is applied to multiple bands, rather than one at a
time?  The "w" parameter would perhaps need to be an array or a list
of matrices.  In this case, the function would be one that requires
all of the bands in the local neighborhood to operate.

--j