library(quadtree)
habitat <- terra::rast(system.file("extdata", "habitat.tif", package="quadtree"))
# create a quadtree
qt <- quadtree(habitat, split_threshold = .1, adj_type = "expand")
# get the cell's neighbors
pt <- c(27000, 10000)
nbs <- get_neighbors(qt, pt)
# plot the neighbors
plot(qt, border_lwd = .3)
points(pt[1], pt[2], col = "black", bg = "lightblue", pch = 21)
with(data.frame(nbs),
rect(xmin, ymin, xmax, ymax, col = "red", border = "black", lwd = 2))
Run the code above in your browser using DataLab