hypertidy / lazyraster

raster data via GDAL on-demand
https://hypertidy.github.io/lazyraster/
27 stars 1 forks source link

lazy reproject #2

Open mdsumner opened 6 years ago

mdsumner commented 6 years ago

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 commented 6 years ago

Problems we hit quickly

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 commented 5 years ago

See internal lazywarp() function