2

after interpolation of sediment classes, I obtained a raster which looks like the image below (sample of the river). I would like to clump and eliminate areas within the raster that are below a certain area. I am open to use R or ArcMap 9.3.

In searching I have come across the Shrink and Expand functions in Arc. However, it doesnt work on my dataset. The function provided on this site looks promising, by applying a moving filter window in the raster package in r. However it does so for a continuous variable, and mine is categorical.

Any suggestions would be welcomed, thanks.

enter image description here

  • In R you may consider a transformation matrix from categorials, i.e. A, B, etc. to integers (1, 2...). That is to overcome the restriction you mentioned. Using the same transformation/concordnace you can reverse the process – dof1985 Mar 31 '15 at 11:34
1

I believe that a sieve approach would work for you. This is a much more robust way to establish a MMU (minimal mapping unit) or filter data that focal approaches.

| improve this answer | |
0

I believe this is what you need to achieve this using R:

# packages
library("raster")
library("igraph")

# load your raster
rast <- raster("your_raster.tif")

Now it might be straightforward to do it for all classes at the same time but I will just illustrate how to do it for class 1, you may do it individually and then unite the results as it's easy to automate:

# copy raster and assign "NA" to all pixels which are not class 1
rast_class_1 <- rast
rast_class_1[rast!=class_1_value]<-NA

# clumped pixels
clumpz <- clump(rast_class_1, directions=8)

# frecuency table of clumps
f <- data.frame(freq(clumpz))

# which rows of the data.frame are only represented by clumps under 8 pixels?
str(which(f$count <= 8))

# which values do these correspond to?
str(f$value[which(f$count <= 8)])

# put these into a vector of clump ID's to be removed
excludeID <- f$value[which(f$count <= 8)]

# exclude these
rast_class_1[clumpz %in% excludeID] <- NA

# write to disk
rf <- writeRaster(rast_class_1, filename="filtered_class_1.tif", format="GTiff", overwrite=TRUE)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.