Aliases: read_stars
Keywords:
### ** Examples tif = system.file("tif/L7_ETMs.tif", package = "stars") (x1 = read_stars(tif))
stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 1 54 69 68.91242 86 255 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA
(x2 = read_stars(c(tif, tif)))
stars object with 3 dimensions and 2 attributes attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 1 54 69 68.91242 86 255 L7_ETMs.tif.1 1 54 69 68.91242 86 255 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA
(x3 = read_stars(c(tif, tif), along = "band"))
stars object with 3 dimensions and 1 attribute attribute(s), summary of first 1e+05 cells: Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 47 65 76 77.3419 87 255 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 12 NA NA NA NA
(x4 = read_stars(c(tif, tif), along = "new_dimensions")) # create 4-dimensional array
stars object with 4 dimensions and 1 attribute attribute(s), summary of first 1e+05 cells: Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 47 65 76 77.3419 87 255 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA new_dimensions 1 2 NA NA NA NA
x1o = read_stars(tif, options = "OVERVIEW_LEVEL=1") t1 = as.Date("2018-07-31") # along is a named list indicating two dimensions: read_stars(c(tif, tif, tif, tif), along = list(foo = c("bar1", "bar2"), time = c(t1, t1+2)))
stars object with 5 dimensions and 1 attribute attribute(s), summary of first 1e+05 cells: Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 47 65 76 77.3419 87 255 dimension(s): from to offset delta refsys point values x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE NULL [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE NULL [y] band 1 6 NA NA NA NA NULL foo 1 2 NA NA NA NA bar1, bar2 time 1 2 2018-07-31 2 days Date NA NULL
m = matrix(1:120, nrow = 12, ncol = 10) dim(m) = c(x = 10, y = 12) # named dim st = st_as_stars(m) attr(st, "dimensions")$y$delta = -1 attr(st, "dimensions")$y$offset = 12 st
stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. A1 1 30.75 60.5 60.5 90.25 120 dimension(s): from to offset delta point x/y x 1 10 0 1 FALSE [x] y 1 12 12 -1 FALSE [y]
tmp = tempfile(fileext = ".tif") write_stars(st, tmp) (red <- read_stars(tmp))
stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. filea3e722cd05ac4.tif 1 30.75 60.5 60.5 90.25 120 dimension(s): from to offset delta x/y x 1 10 0 1 [x] y 1 12 12 -1 [y]
read_stars(tmp, RasterIO = list(nXOff = 1, nYOff = 1, nXSize = 10, nYSize = 12, nBufXSize = 2, nBufYSize = 2))[[1]]
[,1] [,2] [1,] 33 93 [2,] 38 98
(red <- read_stars(tmp, RasterIO = list(nXOff = 1, nYOff = 1, nXSize = 10, nYSize = 12, nBufXSize = 2, nBufYSize = 2)))
stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. filea3e722cd05ac4.tif 33 36.75 65.5 65.5 94.25 98 dimension(s): from to offset delta x/y x 1 2 0 5 [x] y 1 2 12 -6 [y]
red[[1]] # cell values of subsample grid:
[,1] [,2] [1,] 33 93 [2,] 38 98
## Not run: ##D plot(st, reset = FALSE, axes = TRUE, ylim = c(-.1,12.1), xlim = c(-.1,10.1), ##D main = "nBufXSize & nBufYSize demo", text_values = TRUE) ##D plot(st_as_sfc(red, as_points = TRUE), add = TRUE, col = 'red', pch = 16) ##D plot(st_as_sfc(st_as_stars(st), as_points = FALSE), add = TRUE, border = 'grey') ##D plot(st_as_sfc(red, as_points = FALSE), add = TRUE, border = 'green', lwd = 2) ## End(Not run) file.remove(tmp)
[1] TRUE