How to create a raster brick with rasters of different extents? How to create a raster brick with rasters of different extents? r r

How to create a raster brick with rasters of different extents?


here are some things to help you out. Since I don't have your .tif files just some hints. Have you checked the extent on your raster s? It's the size of the world, with just those columns its cells are extremely large. So you have to add an extent to your raster before resampling it. From your info I did something like this:

# create an extent that includes all your datae<-extent(-46, -43, -2, -0.6)# create a raster with that extent, and the number of rows and colums to achive a# similar resolution as you had before, you might have to do some math here....# as crs, use the same crs as in your rasters before, from the crs slots<-raster(e, nrows=7000, ncols=7800, crs=r1@crs)# use this raster to reproject your original raster (since your using the same crs,# resample should work finer1<-resample(r1, s, method="ngb")

Happy Holidays,Ben

PS a better way to find your desired extent & resolution:

# dummy extent from your rasters, instead use lapply(raster list, extent)a<-extent(-45.85728, -43.76855, -2.388705, -0.5181549)b<-extent(-45.87077, -43.78204, -2.388727, -0.5208711) c<-extent(-45.81952 ,-43.7173 , -2.405129 ,-0.5154312)extent_list<-list(a, b, c)# make a matrix out of it, each column represents a raster, rows the valuesextent_list<-lapply(extent_list, as.matrix)matrix_extent<-matrix(unlist(extent_list), ncol=length(extent_list)rownames(matrix_extent)<-c("xmin", "ymin", "xmax", "ymax")# create an extent with the extrem values of your extentbest_extent<-extent(min(matrix_extent[1,]), max(matrix_extent[3,]),min(matrix_extent[2,]), max(matrix_extent[4,]))# the range of your extent in degreesranges<-apply(as.matrix(best_extent), 1, diff)# the resolution of your raster (pick one) or add a desired resolutionreso<-res(r1)# deviding the range by your desired resolution gives you the number of rows and columnsnrow_ncol<-ranges/reso# create your raster with the followings<-raster(best_extent, nrows=nrow_ncol[2], ncols=nrow_ncol[1], crs=r1@crs)