[R-sig-Geo] Get map of non-NA cells of a stack

Johannes Radinger JRadinger at gmx.at
Mon Jun 25 15:45:22 CEST 2012


Hi again,

I want to use the output (!is.na(sum(s))) as a 
'mask' object for the function mask(). I think
I need to get a map which only has 1 and NA values
instead of a logical map?
Can I use the output directly in mask () or how 
do I have to transform the map?


/J
-------- Original-Nachricht --------
> Datum: Mon, 25 Jun 2012 14:42:18 +0200
> Von: "Rafael Wüest" <rafael.wueest at wsl.ch>
> An: Johannes Radinger <JRadinger at gmx.at>
> CC: R-sig-geo at r-project.org
> Betreff: Re: [R-sig-Geo] Get map of non-NA cells of a stack

> Hi Johannes,
> 
> I don't know of any special function, but you can easily obtain this by
> combining sum() and is.na() . See the example below:
> 
> r <- raster(ncols=36, nrows=18)
> r[] <- 1:ncell(r)
> r1<-r;r1[sample(1:ncell(r1),20)]<-NA
> r2<-r;r2[sample(1:ncell(r2),20)]<-NA
> r3<-r;r3[sample(1:ncell(r3),20)]<-NA
> s<-stack(r1,r2,r3)
> 
> s<-addLayer(s,!is.na(sum(s)))
> 
> plot(s)
> 
> This may not be the most efficient way to come up with what you want, as
> summing a big stack may take quite some time, but for small rasters, stacks
> it certainly works...
> 
> HTH, Rafi
> 
> 
> On 25.06.2012, at 10:30, Johannes Radinger wrote:
> 
> > Hi,
> > 
> > I have several stacks with different numbers of raster maps. All the
> stacked rasters have some NA-cells but sometimes in different locations. I'd
> like to create a raster map of a single stack which indicates cells that are
> populated in all rasters of that stack (all non-NA cells).
> > 
> > Is there a special function within the raster package?
> > 
> > Best regards
> > Johannes
> > -- 
> > 
> > Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
> > 
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 
> 
> --
> Rafael Wüest
> Swiss Federal Research Institute WSL
> Zürcherstrasse 111
> 8903 Birmensdorf
> Switzerland
> 
> +41 44 7392126
> rafael.wueest at wsl.ch
> http://www.wsl.ch/info/mitarbeitende/wueest/index_EN
> 
> 
> 

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a



More information about the R-sig-Geo mailing list