1

I have raster data with a resolution of 0.5 degrees. I would like to interpolate these to 0.125 and to 1 degree using nearest neighbour interpolation

How can this be implemented in R? Below is some example data:

library(raster)
ras <- raster(res=0.5)
#get polygons for Iceland
iceland <- getData('GADM', country="Iceland", level=1)
cr <- crop(ras, iceland, snap="out")
values(cr) <- 1:ncell(cr)
fr <- mask(cr, iceland)

plot(fr)
lines(iceland)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
code123
  • 2,082
  • 4
  • 30
  • 53
  • This should get you there as addresses both up and down resolution [raster::aggregate](https://stackoverflow.com/questions/32278825/how-to-change-the-resolution-of-a-raster-layer-in-r), with a number of approaches and raster nuance wrinkles, HTH – Chris Jul 20 '20 at 15:44
  • please make a reproducible by including some example data (not a file; unless it ships with R)l you can use `raster()`. and please use a small area. Use Iceland, not Canada. – Robert Hijmans Jul 20 '20 at 16:52
  • @RobertHijmans Thank you, Robert. Done! – code123 Jul 20 '20 at 17:26
  • Thanks. The resolution is 0.5 degrees. What do you want it to be? – Robert Hijmans Jul 20 '20 at 19:26
  • @RobertHijmans 0.125 degree and 1 degree. – code123 Jul 21 '20 at 00:13

1 Answers1

1

Example data

library(raster)
ras <- raster(res=0.5)
#get polygons for Iceland
iceland <- getData('GADM', country="Iceland", level=1)
cr <- crop(ras, iceland, snap="out")
values(cr) <- 1:ncell(cr)
fr <- mask(cr, iceland)

1 degree

a <- aggregate(fr, 2, mean, na.rm=TRUE)
 

0.125 degree

d <- disaggregate(fr, 4)

Dis-aggregating data like that may be practical, but it may not be appropriate. It obviously is not a good way to change the resolution of climate data (but you asked how to do it, and that is what this site is for)

If the new resolution cannot be obtained by multiplying or dividing with an integer, there is resample

target <- raster(fr)
res(target) <- 1/13
r <- resample(fr, target, "ngb")

#or alternatively
rb <- resample(fr, target, "bilinear")
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63