Consider a grid cell, where each cell is 10x10.
library(sf)
grid1 <- st_make_grid()
plot(grid1)
I would like to create another grid cell, based on grid1
, where each cell is 30x30 and consists of 9 10x10 neighboring cells.
I have very few clues as to how to do it, but I'd rather prefer an sf
solution. I've tried with st_buffer
, but it creates a buffer around each cell. One could perhaps group neighboring cells and aggregate them, but I don't know how to do that either.
Using st_make_grid
's cellsize
parameter, one can make a grid from an existing one and choose the resolution. Using a cellsize of 30 will indeed group the 8 neighboring cells.
grid2 <- st_make_grid(grid1, cellsize = 30)
plot(grid2, lwd = 3)
plot(grid1, add = TRUE, col = NA)
Note that this works because the grid is made of squares; st_make_grid
might not recover the neighboring elements if they are not squares.