tif <- "gebco/GEBCO_2019.tif"
library(vapour)
info <- vapour_raster_info(tif)
## vapour create doesn't work, so I used command line to instantiate the file:
# gdal_create -if gebco/GEBCO_2019.tif file.tif -co SPARSE_OK=YES -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 -co TILED=YES -co COMPRESS=LZW -co BIGTIFF=YES
## my tiling is 512x512 so I read 4x that (more blocks takes longer, but don't make the block too big)
tiles <- grout::tile_index(grout::grout(info$dimension, info$extent, blocksize = info$block * 4))
system.time({
for (i in seq_len(nrow(tiles))) {
offset <- unlist(tiles[i, c("offset_x", "offset_y")])
## the ncol/nrow handles the "dangle" left by tiles, grout sorts it out
dimension <- unlist(tiles[i, c("ncol", "nrow")])
data <- vapour_read_raster_dbl(tif, window = c(offset, dimension))/10000
vapour_write_raster_block("file.tif", data, offset = offset, dimension = dimension, overwrite = TRUE)
if (i %% 10 == 0) print(i)
}
})
Last active
April 28, 2023 13:19
-
-
Save mdsumner/abc467acfb747af3c5d20fe6447cdef8 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment