I have 20 rasters with the same coordinate system but with different extent. I want to set the same extent to them, based on an extent of a shapefile which is at the same coordinate system with the rasters. Also, the new rasters that will be created, I want them to retain their original names.
If some rasters have smaller extent compare to the shapefile, I want the new extent (of the rasters) to be filled with null values.
Could you please guide me on how I can do that, by giving me a step by step instructions?
Here is what I have done so far:
#Reading the shapefile (keep the extent for later)
myshp = readOGR("shapefile.shp")
Getting the spatial extent of the shapefile
e = extent(myshp)
Reading the rasters
r = list.files(path="my_dir",full.names = TRUE, pattern = "\.tif$")