Search code examples
rrasterterra

Expand spatial exent of a raster using another raster


I was wondering if anyone knows how I could extend (physically and in dimension) the spatial extent of a small raster to match a bigger raster. I have used the "extend" function in terra but it's just returning the same size. I have tried the same thing in ArcGIS Pro with raster calculator but no luck. The part that I need to extend is the northernmost part of the small image. The extended part will be filled with zero.

The data are here: https://drive.google.com/drive/folders/1c5AZS9onKUOzNoIVw3py3QFIRxITCjZ_?usp=sharing

Here are the raster info

>large 

class       : SpatRaster 
dimensions  : 762, 762, 1  (nrow, ncol, nlyr)
resolution  : 3100, 3100  (x, y)
extent      : -3034878, -672677.7, 2022791, 4384991  (xmin, xmax, ymin, ymax)
coord. ref. : Canada_Lambert_Conformal_Conic 
source      : Yukon_poly_raster_project.tif 
name        : Yukon_poly_raster_project 
min value   :                         0 
max value   :                       127 

Lager image: note the top part

>small 

class       : SpatRaster 
dimensions  : 426, 400, 1  (nrow, ncol, nlyr)
resolution  : 3096.673, 3098.812  (x, y)
extent      : -2284678, -1046008, 2551588, 3871682  (xmin, xmax, ymin, ymax)
coord. ref. : Canada_Lambert_Conformal_Conic 
source      : FRT_Canada_yukon_ras_1.tif 
name        : FRT_Canada_yukon_ras_1 
min value   :                      3 
max value   :                     11 

Small raster: the northern most part is croped off compared to the large image

Here's my R code:

library(terra)
r = extend(small, large)

Solution

  • What is not working with your R code? The results with extend look good to me.

    library(terra)
    #terra 1.7.38
    
    large <- rast(nrow=762, ncol=762, ext=c(-3034878, -672677.7, 2022791, 4384991))
    small <- rast(nrow=426, ncol=400, ext=c(-2284678, -1046008, 2551588, 3871682))
    
    e <- extend(small, large)
    e
    #class       : SpatRaster 
    #dimensions  : 763, 763, 1  (nrow, ncol, nlyr)
    #resolution  : 3096.675, 3098.812  (x, y)
    #extent      : -3034073, -671310.3, 2021691, 4386085  (xmin, xmax, ymin, ymax)
    #coord. ref. :  
    
    plot(ext(e), lwd=3)
    lines(ext(small), col="red", lwd=2)
    

    But I take it that what you are after is, in this case:

    z <- resample(small, large)