R Under development (unstable) (2023-08-09 r84924 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > suppressPackageStartupMessages(library(stars)) > library(sf) > #jp2 = system.file("jp2/B01.jp2", package = "stars") > #(x = read_stars(jp2, options = c("OVERVIEW_LEVEL=3"))) > tif = system.file("tif/L7_ETMs.tif", package = "stars") > #(x = read_stars(tif, options = c("OVERVIEW_LEVEL=3"))) # FIXME: breaks on windows > (x = read_stars(tif)[,1:20,1:20]) stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 17 44 58 58.19667 70 130 dimension(s): from to offset delta refsys point x/y x 1 20 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 20 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > # names(x) = "L7_ETM" > > # library(abind) > # x = adrop(x) > image(x) > (sfc = st_as_sfc(x, as_points = FALSE)) Geometry set for 400 features Geometry type: POLYGON Dimension: XY Bounding box: xmin: 288776.3 ymin: 9120191 xmax: 289346.3 ymax: 9120761 Projected CRS: SIRGAS 2000 / UTM zone 25S First 5 geometries: POLYGON ((288776.3 9120761, 288804.8 9120761, 2... POLYGON ((288804.8 9120761, 288833.3 9120761, 2... POLYGON ((288833.3 9120761, 288861.8 9120761, 2... POLYGON ((288861.8 9120761, 288890.3 9120761, 2... POLYGON ((288890.3 9120761, 288918.8 9120761, 2... > plot(sfc, add =TRUE) > (sfc = st_as_sfc(x, as_points = TRUE)) Geometry set for 400 features Geometry type: POINT Dimension: XY Bounding box: xmin: 288790.5 ymin: 9120205 xmax: 289332 ymax: 9120747 Projected CRS: SIRGAS 2000 / UTM zone 25S First 5 geometries: POINT (288790.5 9120747) POINT (288819 9120747) POINT (288847.5 9120747) POINT (288876 9120747) POINT (288904.5 9120747) > plot(sfc, add = TRUE) > > sf = st_as_sf(x, as_points = FALSE) > plot(sf, border = NA) > sf = st_as_sf(x[,,,1], as_points = FALSE, merge = TRUE) > plot(sf, border = NA) > > sfc1 <- st_as_sfc(x, as_points = TRUE, use_cpp = TRUE, na.rm = FALSE) > sfc2 <- st_as_sfc(x, as_points = TRUE, use_cpp = FALSE) > identical(sfc1, sfc2) [1] TRUE > > sfc1 <- st_as_sfc(x, as_points = FALSE, use_cpp = TRUE, na.rm = FALSE) > sfc2 <- st_as_sfc(x, as_points = FALSE, use_cpp = FALSE) > identical(sfc1, sfc2) [1] TRUE > > # sf -> stars -> sf > x = st_sfc(st_point(0:1), st_point(1:2), st_point(2:3)) > m = matrix(1:9,3) > colnames(m) = c("a", "b", "c") > foo = st_sf(m, geom = x) > x = st_as_stars(foo) > c(x) stars object with 1 dimensions and 3 attributes attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. a 1 1.5 2 2 2.5 3 b 4 4.5 5 5 5.5 6 c 7 7.5 8 8 8.5 9 dimension(s): from to point values geom 1 3 TRUE POINT (0 1),...,POINT (2 3) > st_redimension(x) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. a.b.c 1 3 5 5 7 9 dimension(s): from to point values geom 1 3 TRUE POINT (0 1),...,POINT (2 3) new_dim 1 3 NA a, b, c > c(x, x) stars object with 1 dimensions and 6 attributes attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. a 1 1.5 2 2 2.5 3 b 4 4.5 5 5 5.5 6 c 7 7.5 8 8 8.5 9 a.1 1 1.5 2 2 2.5 3 b.1 4 4.5 5 5 5.5 6 c.1 7 7.5 8 8 8.5 9 dimension(s): from to point values geom 1 3 TRUE POINT (0 1),...,POINT (2 3) > (y = st_redimension(x, along = list(time = as.Date("2017-11-27") + 0:2))) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. a.b.c 1 3 5 5 7 9 dimension(s): from to offset delta refsys point values geom 1 3 NA NA NA TRUE POINT (0 1),...,POINT (2 3) time 1 3 2017-11-27 1 days Date NA NULL > st_as_sf(y) Simple feature collection with 3 features and 3 fields Geometry type: POINT Dimension: XY Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 3 CRS: NA 2017-11-27 2017-11-28 2017-11-29 geom 1 1 4 7 POINT (0 1) 2 2 5 8 POINT (1 2) 3 3 6 9 POINT (2 3) > st_as_sf(st_as_stars(foo)) Simple feature collection with 3 features and 3 fields Geometry type: POINT Dimension: XY Bounding box: xmin: 0 ymin: 1 xmax: 2 ymax: 3 CRS: NA a b c geom 1 1 4 7 POINT (0 1) 2 2 5 8 POINT (1 2) 3 3 6 9 POINT (2 3) > > c(x,x,along=1) # NEEDS FIXING! stars object with 1 dimensions and 3 attributes attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. a 1 1.25 2 2 2.75 3 b 4 4.25 5 5 5.75 6 c 7 7.25 8 8 8.75 9 dimension(s): from to point values geom 1 6 TRUE POINT (0 1),...,POINT (2 3) > # st_as_stars.sfc > st_as_stars(st_geometry(st_as_sf(y)), nx = 10, ny = 10, as_points = FALSE) stars object with 2 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. values 0 0 0 0.06 0 1 dimension(s): from to offset delta x/y x 1 10 0 0.2 [x] y 1 10 3 -0.2 [y] > > proc.time() user system elapsed 1.23 0.28 1.50