[R-sig-Geo] Raster package - Focal sum in circles

Robert J. Hijmans r.hijmans at gmail.com
Mon Jan 26 19:27:28 CET 2015


Your focal weights sum to 1, such that you get the mean value when
using 'fun=sum'
if you want to sum, you can do

fw <- focalWeight(x, 50, type='circle')
fw[fw>0] <- 1

p_focal<-focal(x, w=fw,fun=sum , na.rm=TRUE)


Robert

On Mon, Jan 26, 2015 at 3:17 AM, Vanessa Machault
<vanessamachault at yahoo.com.br> wrote:
> Hi,
> I have a question regarding the package "raster" and the function "focal".
> I have a raster with 0.5m pixels and I would like to calculate the sum of all pixels in 50m radius circles, with a moving window.I have some NA values and I need to ignore them in the calculation.
> Then, I would create a new raster where all the pixels that are not NA would be filled with the sum value.
> I tried with "focal" and "focal weight" but nothing comes close to the result.Example :fw <- focalWeight(x, 50, type='circle')
> p_focal<-focal(x, w=fw,fun=sum , na.rm=TRUE)
> I saw that several way of writing those focal stats may lead to different computation times. Here, as I need to repeat the process for a large number of rasters, computation time may be an issue.
> I thank you very much in advance for your help.Regards,Vanessa Machault
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list