patchscan | R Documentation |
This function takes a matrix or grid object in which cover type is classified and returns an object of the same class (grid or matrix) containing the patch id of each cell.
patchscan(x, nr = 8, na.value = -9999)
## S3 method for class 'grid'
patchscan(x, nr = 8, na.value = -9999)
## S3 method for class 'matrix'
patchscan(x, nr = 8, na.value = -9999)
x |
Either a matrix or a grid object. |
nr |
The neighbor rule either 4 or 8 indicating that either the 4 orthogonal neighboring cells or the 8 orthogonal and diagonal neighboring cells are considered neighbors. |
na.value |
The value used to encode NA's when passing data to C. |
#
patches |
An object of the same class as |
count |
A count of the number of patches in the landcape. |
Ethan Plunkett
grid-class
m <- matrix(sample(1:4, 400, replace=TRUE) , 20, 15)
g <- list(m=m, nrow=nrow(m), ncol=ncol(m), xll=0, yll=20, cellsize=1)
class(g) <- c("grid", class(g))
# With default arguments
res <- patchscan(g)
# With NA's in grid
g$m[2:3, 4] <- NA
res <- patchscan(g)
plot(res$patches, na.col="red")
# Using 4 neighbor rule (8 is the default)
res <- patchscan(g, nr=4)
plot(res$patches)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.