lazyraster icon indicating copy to clipboard operation
lazyraster copied to clipboard

lazy reproject

Open mdsumner opened this issue 7 years ago • 2 comments

This was surprisingly effective (x$info$projection must be valid, and often is not).

lazyproject <- function(x, xylim, crs) {
   rr <- raster(xmn = xmin(xylim), 
                xmx = xmax(xylim), ymn = ymin(xylim), ymx = ymax(xylim), crs = crs, 
          nrows = 300, ncols = 300)
   tt <- as_raster(lazycrop(x, projectExtent(rr, x$info$projection)))
   projection(tt) <- x$info$projection
   projectRaster(tt, rr)
}

mdsumner avatar Aug 20 '18 10:08 mdsumner

Problems we hit quickly

  • data is not scaled by GDAL, as it is by ncdf4
  • seams at the edges ..
  • x$info$projection must be valid, and often is not

So a raadtools-like wrapper is pretty necessary to provide curated products

But, this will be awesome for fast map creation, this is fast enough to watch:

files <- raadtools::sstfiles()
x <- lazyraster(files$fullname[1])
x$info$projection <- "+proj=longlat +datum=WGS84"
sstpal <- palr::sstPal(100)[1:50]
e <- new("Extent", xmin = -2641144.09507382, xmax = 1289641.22311962, 
    ymin = 1409623.24488862, ymax = 3887209.14241661)
for (i in seq(1, 100, by = 1)) {
  x$source <- files$fullname[i]
  plot(lazyproject(x, e, projection(sfdct::antarctica))/100, zlim = c(-2, 10), col = sstpal)
}

mdsumner avatar Aug 20 '18 11:08 mdsumner

See internal lazywarp() function

mdsumner avatar Oct 03 '19 12:10 mdsumner