Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/usr/bin/env Rscript
  2.  
  3. library(raster)
  4.  
  5. # Create gridded example data
  6. xyz <- expand.grid(x = seq(-112.4, -111.6, by = 0.03),
  7. y = seq(40.3, 40.9, by = 0.03))
  8. xyz$z <- with(xyz, abs(x * y))
  9. r_coarse <- rasterFromXYZ(xyz, crs = '+proj=longlat')
  10. r_coarse
  11. # class : RasterLayer
  12. # dimensions : 21, 27, 567 (nrow, ncol, ncell)
  13. # resolution : 0.03, 0.03 (x, y)
  14. # extent : -112.415, -111.605, 40.285, 40.915 (xmin, xmax, ymin, ymax)
  15. # coord. ref. : +proj=longlat +ellps=WGS84
  16. # data source : in memory
  17. # names : z
  18. # values : 4498.286, 4597.16 (min, max)
  19.  
  20. xres <- 0.01
  21. yres <- 0.01
  22. r_interpolated <- projectRaster(r_coarse,
  23. res = c(xres, yres),
  24. crs = '+proj=longlat',
  25. method = 'bilinear')
  26. r_interpolated
  27. # class : RasterLayer
  28. # dimensions : 73, 91, 6643 (nrow, ncol, ncell)
  29. # resolution : 0.01, 0.01 (x, y)
  30. # extent : -112.465, -111.555, 40.235, 40.965 (xmin, xmax, ymin, ymax)
  31. # coord. ref. : +proj=longlat +ellps=WGS84
  32. # data source : in memory
  33. # names : z
  34. # values : 4496.767, 4598.693 (min, max)
  35.  
  36. op <- par(mfrow = c(1, 2))
  37. plot(r_coarse, main = 'Coarse', col = viridis::viridis(256))
  38. plot(r_interpolated, main = 'Interpolated', col = viridis::viridis(256))
  39. par(op)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement