lazyraster
lazyraster copied to clipboard
lazy reproject
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)
}
Problems we hit quickly
- data is not scaled by GDAL, as it is by ncdf4
- seams at the edges ..
x$info$projectionmust 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)
}
See internal lazywarp() function