
R Under development (unstable) (2026-02-12 r89409 ucrt) -- "Unsuffered Consequences"
Copyright (C) 2026 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))
> tif = system.file("tif/L7_ETMs.tif", package = "stars")
> x = read_stars(tif)
> (a = st_area(x[,1:5,1:5]))
stars object with 2 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median   Mean 3rd Qu.   Max.
area [m^2] 812.25  812.25 812.25 812.25  812.25 812.25
dimension(s):
  from to  offset delta                     refsys point x/y
x    1  5  288776  28.5 SIRGAS 2000 / UTM zone 25S FALSE [x]
y    1  5 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y]
> 
> m = matrix(1:20, nrow = 5, ncol = 4)
> x = c(0, 0.5, 1, 2, 4, 5)  # 6 numbers: boundaries!
> y = c(0.3, 0.5, 1, 2, 2.2) # 5 numbers: boundaries!
> (r = st_as_stars(list(m = m), dimensions = st_dimensions(x = x, y = y)))
stars object with 2 dimensions and 1 attribute
attribute(s):
   Min. 1st Qu. Median Mean 3rd Qu. Max.
m     1    5.75   10.5 10.5   15.25   20
dimension(s):
  from to point                values x/y
x    1  5 FALSE     [0,0.5),...,[4,5) [x]
y    1  4 FALSE [0.3,0.5),...,[2,2.2) [y]
> # image(r, axes = TRUE, col = grey((1:20)/20))
> (a = st_area(r))
Missing coordinate reference system: assuming Cartesian coordinates
stars object with 2 dimensions and 1 attribute
attribute(s):
      Min. 1st Qu. Median  Mean 3rd Qu. Max.
area   0.1     0.2  0.325 0.475     0.5    2
dimension(s):
  from to point                values x/y
x    1  5 FALSE     [0,0.5),...,[4,5) [x]
y    1  4 FALSE [0.3,0.5),...,[2,2.2) [y]
> #plot(a, axes = TRUE)
> 
> s5p = system.file("sentinel5p/S5P_NRTI_L2__NO2____20180717T120113_20180717T120613_03932_01_010002_20180717T125231.nc", package = "starsdata")
> if (s5p != "") {
+  nit.c = read_stars(s5p, sub = "//PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/nitrogendioxide_summed_total_column",
+ 	curvilinear = c("//PRODUCT/longitude", "//PRODUCT/latitude"), driver = NULL)
+  if (inherits(nit.c[[1]], "units"))
+ 	nit.c[[1]] = units::drop_units(nit.c[[1]])
+  nit.c[[1]][nit.c[[1]] > 9e+36] = NA
+  st_crs(nit.c) = 4326
+  print((a <- st_area(nit.c[,1:5,1:5])))
+  # plot(a, axes = TRUE, border = NA)
+ }
> 
> proc.time()
   user  system elapsed 
   1.18    0.28    1.40 
