[R-sig-Geo] Assign a unique ID number to each patch in a raster
Nelly Reduan
nell.redu at hotmail.fr
Thu Jan 26 22:48:17 CET 2017
Hello,
I would like to assign a unique ID number to each patch (a patch is composed of a set of adjacent cells) as shown in this figure:
[cid:bab831e5-4246-4a77-884c-0012101662a5]
I tested the clump function (package raster) by applying an eight adjacent cells rule but this function mixes all cell values into single patch.
Here is a code example to create a raster. The raster contains values ranged from 1 to 9.
r <- raster(ncols=12, nrows=12)
r[] <- round(runif(ncell(r),1,9),digits=0)
plot(r)
Is there a way to assign a unique ID number to grouping cells that form a patch for each class (i.e., values 1, 2, 3, 4, 5, 6, 7, 8, 9) ?
Thanks a lot for your time
Nell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170126/31adc96e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2328.png
Type: image/png
Size: 35110 bytes
Desc: 2328.png
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170126/31adc96e/attachment.png>
More information about the R-sig-Geo
mailing list