[R-sig-Geo] windowed reading raster with stars

Loïc Dutrieux |o|c@dutr|eux @end|ng |rom c|r@d@|r
Sat Apr 25 17:14:58 CEST 2020


Hi everyone,

I have a large geoTiff raster file that does not fit in memory (if I do 
read_stars(file_path) I get "Error: cannot allocate vector of size 12.7 
Gb"). How can I read a spatial subset of that file.

The example below works with a toy example but not with the actual large 
dataset.

library(stars)
library(sf)

tif = system.file("tif/L7_ETMs.tif", package = "stars")
window <- read_stars(tif) %>%
     st_bbox() %>%
     st_as_sfc() %>%
     st_buffer(-2000) %>%
     st_bbox()

tif_sub <- read_stars(tif, proxy = TRUE) %>%
     st_crop(window)

plot(tif_sub)

I get the following error:

Error in x[[i]][1:-21561856, 1:146, , drop = FALSE] :
   only 0's may be mixed with negative subscripts

Kind regards,
Loïc



More information about the R-sig-Geo mailing list