
R version 3.6.0 (2019-04-26) -- "Planting of a Tree"
Copyright (C) 2019 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))
> geomatrix = system.file("tif/geomatrix.tif", package = "stars")
> (x = read_stars(geomatrix))
stars object with 2 dimensions and 1 attribute
attribute(s):
 geomatrix.tif  
 Min.   : 74.0  
 1st Qu.:107.0  
 Median :123.0  
 Mean   :126.8  
 3rd Qu.:132.0  
 Max.   :255.0  
dimension(s):
  from to  offset delta                       refsys point values    
x    1 20 1841002   1.5 +proj=utm +zone=11 +datum...  TRUE   NULL [x]
y    1 20 1144003  -1.5 +proj=utm +zone=11 +datum...  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))
> library(lwgeom)
Linking to liblwgeom 2.5.0dev r16016, GEOS 3.7.0, PROJ 5.2.0
> x__ = st_transform_proj(x, st_crs(4326)$proj4string)
> 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):
  L7_ETMs.tif   
 Min.   :25.00  
 1st Qu.:43.00  
 Median :51.00  
 Mean   :50.72  
 3rd Qu.:60.00  
 Max.   :74.00  
dimension(s):
         from  to offset delta                       refsys point
geometry    1 100     NA    NA +proj=longlat +datum=WGS8... 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):
  L7_ETMs.tif   
 Min.   :25.00  
 1st Qu.:43.00  
 Median :51.00  
 Mean   :50.72  
 3rd Qu.:60.00  
 Max.   :74.00  
dimension(s):
         from  to offset delta                       refsys point
geometry    1 100     NA    NA +proj=longlat +datum=WGS8... 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 
  0.613   0.046   0.650 
