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

Vanessa Machault vanessamachault at yahoo.com.br
Tue Jan 27 10:55:50 CET 2015


Thanks a lot Robert it works perfectly well.And the pixels that are NA are correctly omitted.

In addition, I just would like to know if it is possible to restrict the calculation to the pixels that are not NA (kind of masking ?).Indeed, the resulting raster contains all the pixels of the extend. 
But I have a lot of empty pixels on which focal stats do not need to be calculated.This of course is for questions of calculation time...

Thanks a lot in advance.RegardsVanessa.

 

     Le Lundi 26 janvier 2015 19h27, Robert J. Hijmans <r.hijmans at gmail.com> a écrit :
   

 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


   
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list