library(terra)
rast1 <- rast(ncol=10, nrow=10)
values(rast1) <- rep(0:1, 50)
rast2 <- rast(ncol=10, nrow=10)
values(rast2) <- c(rep(0, 50), rep(1,50))
testIntersection(rast1, rast2)
rast1 <- crop(rast1, ext(10, 20, 30, 40))
rast2 <- crop(rast2, ext(-20, -10, -40, -30))
testIntersection(rast1, rast2)
Run the code above in your browser using DataLab