6

I need to stack multiple maps (tif) together and clip them all according to extent of one small raster map (second raster at the top of picture below). However, the size of pixels in each map is different. Is there any way how to make process visualized bellow?

Please, answer only R-solution or QGIS-solution.

enter image description here

library(raster)
e1<-extent(c(0,6,0,6))
r1<-raster(nrows=3,ncols=3,ext=e1)
values(r1)<-c(0,4,1,0,1,1,1,2,3)
plot(r1)
e2<-extent(c(2,5,2,5))
r2<-raster(nrows=4,ncols=3,ext=e2)
values(r2)<-c(0,8,2,1,4,9,9,4,0,8,0,0)
plot(r2)
TsvGis
  • 2,079
  • 18
  • 35
Ladislav Naďo
  • 267
  • 3
  • 10
  • 2
    Steps to take: (1) Resample both rasters to same samplesize (2) Unify their extents ether by cropping or extending (3) Stack them and mask with your other raster – Curlew Aug 08 '15 at 18:30

1 Answers1

8

You can:

Load required libraries:

library(raster)
library(rgdal)

Read rasters:

r1 = raster("./dir/r1.tif")
r2 = raster("./dir/r2.tif")

Resample to the finer grid

r.new = resample(r1, r2, "bilinear")

If required (for masking), set extents to match

ex = extent(r1)
r2 = crop(r2, ex)

Removed unrequired data

r.new = mask(r.new, r2)
MikeRSpencer
  • 972
  • 6
  • 12