
R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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))
> suppressPackageStartupMessages(library(lwgeom))
> geomatrix = system.file("tif/geomatrix.tif", package = "stars")
> (x = read_stars(geomatrix))
stars object with 2 dimensions and 1 attribute
attribute(s):
               Min. 1st Qu. Median    Mean 3rd Qu. Max.
geomatrix.tif    74     107    123 126.765     132  255
dimension(s):
  from to  offset delta                refsys point values x/y
x    1 20 1841002   1.5 WGS 84 / UTM zone 11N  TRUE   NULL [x]
y    1 20 1144003  -1.5 WGS 84 / UTM zone 11N  TRUE   NULL [y]
sheared raster with parameters: -5 -5 
> new = st_crs(4326)
> y = st_transform(x, new)
> plot(st_transform(st_as_sfc(st_bbox(x)), new), col = NA, border = 'red')
> plot(st_as_sfc(y, as_points=FALSE), col = NA, border = 'green', axes = TRUE, add = TRUE)
> image(y, add = TRUE)
> plot(st_as_sfc(y, as_points=TRUE), pch=3, cex=.5, col = 'blue', add = TRUE)
> plot(st_transform(st_as_sfc(x, as_points=FALSE), new), add = TRUE)
> 
> tif = system.file("tif/L7_ETMs.tif", package = "stars")
> x = read_stars(tif)[,1:10,1:10,1:3]
> x_ = st_transform(x, st_crs(4326))
> x__ = st_transform_proj(x, st_crs(4326)$proj4string)
> st_crs(x_) = st_crs(x__)
> all.equal(x_,x__)
[1] TRUE
> 
> # x__ = st_transform(x, x_) #now in st_warp 
> # all.equal(x_, x__)
> 
> x = st_xy2sfc(x, as_points = FALSE)
> (x_ = st_transform(x, st_crs(4326)))
stars object with 2 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median  Mean 3rd Qu. Max.
L7_ETMs.tif    25      43     51 50.72      60   74
dimension(s):
         from  to offset delta refsys point
geometry    1 100     NA    NA WGS 84 FALSE
band        1   3     NA    NA     NA    NA
                                                                    values
geometry POLYGON ((-34.91617 -7.9498...,...,POLYGON ((-34.91385 -7.9521...
band                                                                  NULL
> (x__ = st_transform_proj(x, st_crs(4326)))
stars object with 2 dimensions and 1 attribute
attribute(s):
             Min. 1st Qu. Median  Mean 3rd Qu. Max.
L7_ETMs.tif    25      43     51 50.72      60   74
dimension(s):
         from  to offset delta refsys point
geometry    1 100     NA    NA WGS 84 FALSE
band        1   3     NA    NA     NA    NA
                                                                    values
geometry POLYGON ((-34.91617 -7.9498...,...,POLYGON ((-34.91385 -7.9521...
band                                                                  NULL
> all.equal(x_,x__,check.attributes = FALSE)
[1] TRUE
> 
> # nothing to transform: now errs:
> try(st_transform(st_as_stars(list(matrix(1,10,10))), st_crs(4326)))
Error in st_transform.stars(st_as_stars(list(matrix(1, 10, 10))), st_crs(4326)) : 
  !is.na(st_crs(x)) is not TRUE
> try(st_transform_proj(st_as_stars(list(matrix(1,10,10))), st_crs(4326)))
Error in st_transform_proj.stars(st_as_stars(list(matrix(1, 10, 10))),  : 
  !is.na(st_crs(x)) is not TRUE
> 
> proc.time()
   user  system elapsed 
  1.014   0.041   1.051 
