Let's make an example with some sample rasters that represent your situation, hopefully. First a big raster with extent from (0,0) to (100,100):
big = raster(matrix(1:100,10,10))
extent(big)=c(0,100,0,100)
Now a small raster spanning part of that from (10,20) to (20,30):
small = raster(matrix(1:100,10,10))
extent(small)=c(10,20,20,30)
Now use extend
to expand the bounds of small
to the extent of big
smallextend = extend(small, big)
which is this:
class : RasterLayer
dimensions : 100, 100, 10000 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0, 100, 0, 100 (xmin, xmax, ymin, ymax)
crs : NA
source : memory
names : layer
values : 1, 100 (min, max)
Plotting shows smallextend
stretching out to the extent of big
, but padded with NA
values:
Note the extent might not be exact if the resolution doesn't exactly fit into the big raster, for example:
> extent(small2) = c(11.23, 23.7, 22.1, 33.4)
> plot(small2, add=TRUE)
> extend(small2, big)
class : RasterLayer
dimensions : 89, 80, 7120 (nrow, ncol, ncell)
resolution : 1.247, 1.13 (x, y)
extent : 0.007, 99.767, -0.5, 100.07 (xmin, xmax, ymin, ymax)
crs : NA
source : memory
names : layer
values : 1, 100 (min, max)
you can see the output extent isn't quite the same as big
because the small2
is not made of 1x1 cells.