Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active May 22, 2024 02:00
Show Gist options
  • Save mdsumner/b31a205ee6fae667a50032db0ea9d88c to your computer and use it in GitHub Desktop.
Save mdsumner/b31a205ee6fae667a50032db0ea9d88c to your computer and use it in GitHub Desktop.

## remotes::install_github("USDAForestService/gdalraster") ## since 2024-05-22
library(gdalraster)
dsn <- "NetCDF:/vsicurl/https://www.ncei.noaa.gov/data/sea-surface-temperature-optimum-interpolation/v2.1/access/avhrr/202209/oisst-avhrr-v02r01.20220925.nc:sst"
translate(dsn, tif <- tempfile(fileext = ".tif", 
                               tmpdir = "/vsimem"), 
          cl_arg = c("-a_srs", "EPSG:4326", "-of", "GTiff", "-co", "COMPRESS=ZSTD"))
aa <- new(VSIFile, tif)
bytes <- aa$ingest(-1)

## bytes can now be pushed to S3, or out to file
#writeBin(bytes, temp <- tempfile(fileext = ".tif"))
#terra::rast(temp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment