[R-sig-Geo] Count Pixel with Specific of Values Appearing Sequentially in Rasterstack

John Wasige johnwasige at gmail.com
Sat May 16 18:15:59 CEST 2015


Hi Robert!

I have used your script to count pixels with Specific of Values Appearing
Sequentially in Rasterstack and it works well. It seems not to work for a
situation where am interest in values less than a specific of Value e.g.,
<0 or >0 and are not Appearing Sequentially in Rasterstack. Do you have an
idea how I can deal with counting non Sequential Values Appearing  in
Rasterstack in Rasterstack?

Thanks for your help

John

On Sun, Apr 26, 2015 at 4:44 AM, Robert J. Hijmans <r.hijmans at gmail.com>
wrote:

> Arnold,
>
> In cases like this you can make a function that computes this for a
> vector, test that function, including for a vector of NA values, and,
> if it works, use calc.
>
> # counting runs of 255
> run <- function(x) {
>   x[x != 255] <- NA
>   r <- rle(x)
>   w <- which(!is.na(r$values))
>   ifelse(length(w) > 0, max(r$lengths), 0)
> }
>
> run(rep(NA, 5))
> run(c(255, rep(NA, 5), 255, 255))
> run(rep(255, 5))
>
> # looking good, let's use it
>
> b <- brick(system.file("external/rlogo.grd", package="raster"))
> x <- calc(b, run)
> plot(x)
>
>
> Robert
>
> On Sat, Apr 25, 2015 at 9:10 AM, Arnold Salvacion via R-sig-Geo
> <r-sig-geo at r-project.org> wrote:
> > Dear Colleagues,
> > Any idea on how to count the number of times a particular number (e.g.
> 1) appears consecutively within each pixel of a raster stack/brick? I found
> a similar question online (
> http://grokbase.com/t/r/r-sig-geo/1459p0s978/error-when-attempting-to-use-rle-in-calc-in-raster-package)
> but was not able to view/get any answer to solve such problem.
> > Thanks in advance.
> > Arnold
> >
> >
> >
> >         [[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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
John Wasige
"Birds born in a Cage think Flying is an illness."

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list