[R-sig-Geo] raster::clump not working?
Bede-Fazekas Ákos
bf@levli@t @ending from gm@il@com
Fri May 25 13:00:02 CEST 2018
Dear Joao,
I think function clump() works as it should be. A toy example:
x <- raster(matrix(sample(x = c(NA, NA, NA, 1), size = 36*18, replace =
TRUE), ncol=36, nrow=18))
plot(x)
plot(clump(x))
Maybe you are searching for a function that aggregate those cells that
have the same value?
In this case it would do what you want (I'm sure there is a more
straightforward way...):
r <- raster(ncols=36, nrows=18)
x <- init(r, fun='cell')
y <- layerize(x)
ids <- calc(x = y, fun = function(layers)
{return(which(as.logical(layers))[1])})
plot(ids)
HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences
2018.05.25. 12:00 keltezéssel, João Carreiras írta:
> Hi!
>
> I've been trying to run the clump command but the output is consistently a
> raster with values == 1. Please find below an example.
>
> I'm sure I'm doing something stupid. However, the command is really
> straightforward and I can't seem to identify what the problem might be.
>
> Any help really appreciated.
> Thanks
> Joao
>
> r <- raster(ncols=36, nrows=18)
> x <- init(r, fun='cell')
> x
> class : RasterLayer
> dimensions : 18, 36, 648 (nrow, ncol, ncell)
> resolution : 10, 10 (x, y)
> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names : layer
> values : 1, 648 (min, max)
> a <- clump(x)
> a
> class : RasterLayer
> dimensions : 18, 36, 648 (nrow, ncol, ncell)
> resolution : 10, 10 (x, y)
> extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names : clumps
> values : 1, 1 (min, max)
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list