I have a classified Landsat image, and I'd like to pass a filter over it converting certain cells to 0. For some categories, I'd like to set cells to 0 unless an entire 7x7 window contains only that cell value. For other categories, I'd like to set cells to 0 unless an entire 5x5 window contains only that cell value. And for others, set to 0 unless at 3x3 window, etc. I've tried two ways to do this:
One is to pass multiple filters over the same raster, and then combine their outputs. I tried this and it takes an incredibly long time, so I think it would be more efficient to pass one 7x7 filter over the raster, and have a conditional function that subsets the window to 5x5 or 3x3 based on the value of the category it is passing over.
However, it doesn't seem to be working, I think because I am having trouble referencing the 3x3 sub window within the 7x7 moving window. How can I write a function to be used within the focal() function that references only certain cells within the moving window?
The code I am using:
r 1 and only the first element will be used4: In if (cells[c(seq(9, 13), seq(16, 20), seq(23, 27), seq(30, ... : the condition has length > 1 and only the first element will be used5: In if (cells[c(seq(9, 13), seq(16, 20), seq(23, 27), seq(30, ... : the condition has length > 1 and only the first element will be used6: In if (cells[c(seq(9, 13), seq(16, 20), seq(23, 27), seq(30, ... : the condition has length > 1 and only the first element will be used7: In if (cells == rep(3, 49)) { ... : the condition has length > 1 and only the first element will be used8: In if (cells[c(17, 18, 19, 24, 25, 26, 31, 32, 33)] == ... : the condition has length > 1 and only the first element will be used9: In if (cells[c(17, 18, 19, 24, 25, 26, 31, 32, 33)] == ... : the condition has length > 1 and only the first element will be used10: In if (cells[c(17, 18, 19, 24, 25, 26, 31, 32, 33)] == ... : the condition has length > 1 and only the first element will be used
أكثر...
One is to pass multiple filters over the same raster, and then combine their outputs. I tried this and it takes an incredibly long time, so I think it would be more efficient to pass one 7x7 filter over the raster, and have a conditional function that subsets the window to 5x5 or 3x3 based on the value of the category it is passing over.
However, it doesn't seem to be working, I think because I am having trouble referencing the 3x3 sub window within the 7x7 moving window. How can I write a function to be used within the focal() function that references only certain cells within the moving window?
The code I am using:
r 1 and only the first element will be used4: In if (cells[c(seq(9, 13), seq(16, 20), seq(23, 27), seq(30, ... : the condition has length > 1 and only the first element will be used5: In if (cells[c(seq(9, 13), seq(16, 20), seq(23, 27), seq(30, ... : the condition has length > 1 and only the first element will be used6: In if (cells[c(seq(9, 13), seq(16, 20), seq(23, 27), seq(30, ... : the condition has length > 1 and only the first element will be used7: In if (cells == rep(3, 49)) { ... : the condition has length > 1 and only the first element will be used8: In if (cells[c(17, 18, 19, 24, 25, 26, 31, 32, 33)] == ... : the condition has length > 1 and only the first element will be used9: In if (cells[c(17, 18, 19, 24, 25, 26, 31, 32, 33)] == ... : the condition has length > 1 and only the first element will be used10: In if (cells[c(17, 18, 19, 24, 25, 26, 31, 32, 33)] == ... : the condition has length > 1 and only the first element will be used
أكثر...