I have two different raster layers with different masked areas. They overlap by a few pixels, which is desired. So i want to merge both layers with the overlapping values "smoothly" transitioning. However, with the terra package best i can get is fun = "mean". Ive constructed an example, which shows what i did:
library(terra)
r <- rast(ncols = 36, nrows = 18)
r[450] <- 1
r <- 1 * buffer(r, width = 5000000)
r[r == 0] <- NA
plot(r)
b <- rast(ncols = 36, nrows = 18)
b[345] <- 1
b <- 1 * buffer(b, width = 5000000)
b[b == 1] <- 5
b[b == 0] <- NA
plot(b)
m <- mosaic(r, b, fun = "mean")
plot(m)
The problem now is, that i want the transition between r and b to be smooth and not just mean. So there should be a transition from e.g. 2, 3, 4 from r to b in the overlapping pixels. Can anyone help me here? I haven't found any similar problem online, to be honest, i don't even know what to search for in this case.
Thanks in regards.
These series look 'rowish', two rle-like views, cgwtools::seqle gives rle of sequences
The lengths are of interest as they suggest the allocation of 2,3,4 transitioning to 5, but is the logic that it should happen up or across? Given that 50:55 is both downmost and closest to 1 values, perhaps these are your 2(s). How 2,3,4,5 are allocated, up or across, more 2s than 3s, might be indicated by your data.
Consider that this might be a completely foolish approach, though one I'd likely employ myself, and others may provide better guidance. But, continuing on into the fog
Now have something to reason about relative a gradient, and looked at in context of plotting r, b, and rb_intersect we see defensible decisions need making where rb_mtx_01[9, 17] <- could be 3, but [9, 18:20] <- should be 5. Make your decisions for these TRUE(s). Make another index for the FALSE(s) assigning 1 or 5.
rb_gradient <- rast(rb_mtx_01), and you've got a gradient that hopefully reflects reality. With your FALSE indexAs mentioned, plenty of hand work, even in this small example. It is useful, none the less, when producing counter-factual data where (returning to elevation), the satellite data says the river goes here, the river got 'moved' 500 years ago and you're trying to model the river 800 years ago. Hand work.