On Wed, 12 Mar 2008, Agustin Lobo wrote:

and a combination of r.clump and r.stats
in grass (which is "linked" to R) can also do the job.

Yes, that will be very robust. I've tried an R attack through neighbour lists:

library(sp)
data(meuse.grid)
coordinates(meuse.grid) <- c("x", "y")
gridded(meuse.grid) <- TRUE
fullgrid(meuse.grid) <- TRUE
class(meuse.grid)
names(meuse.grid)
meuse.grid$ffreq1 <- meuse.grid$ffreq == 1
is.na(meuse.grid$ffreq1) <- !meuse.grid$ffreq1
image(meuse.grid, "ffreq1")
pix <- as(meuse.grid["ffreq1"], "SpatialPixelsDataFrame")
summary(pix)
image(pix)
library(spdep)
nb_rook <- dnearneigh(coordinates(pix), 0, 41)
nb_queen <- dnearneigh(coordinates(pix), 0, 57)
comp_rook <- n.comp.nb(nb_rook)
comp_queen <- n.comp.nb(nb_queen)
t_rook <- table(comp_rook$comp.id)
t_queen <- table(comp_queen$comp.id)
t_rook
t_queen
pix$rook <- comp_rook$comp.id
pix$queen <- comp_queen$comp.id
image(pix, "rook", col=rainbow(31))
pix$nrook <- t_rook[pix$rook]
pix$nqueen <- t_queen[pix$queen]
summary(pix)
image(pix, "nqueen")
spplot(pix, "nqueen")

using cut-off distances for distance-based neighbours just larger than the resolution and the diagonal resolution. There were only 779 cells in patches here, but it ran so fast that scaling up shouldn't be a problem.

Roger


Agus

Andrew Niccolai escribió:
If you aren't dedicated to an R specific solution, ImageJ is open source and
does this under Analysis/Binary.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Murray Richardson
Sent: Wednesday, March 12, 2008 12:59 PM
To: r-sig-geo@stat.math.ethz.ch
Subject: [R-sig-Geo] enumerate grid clusters/patches with size of contiguous
cluster

Hello friends,

I am trying to take a binary input grid of patches (connected cells with
value = 1), and assign to each non-zero cell the total number of pixels
comprising the patch to which it belongs.

So for a connected patch of 27 pixels, all cells belonging to that patch
will have a value of 27.

Just wondering if anyone has any suggestions.  Maybe a function I don't
know about yet...

Thanks in advance,

Murray Richardson

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo




--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to