
R version 4.1.1 (2021-08-10) -- "Kick Things"
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))
> geomatrix = system.file("tif/geomatrix.tif", package = "stars")
> x = read_stars(geomatrix)
> # can stars reproduce what gdal does, by default?
> x2 = st_warp(x, use_gdal = TRUE, no_data_value = -9999)
> y = st_warp(x, x2)
> plot(x2, breaks = "equal", axes=TRUE)
> plot(y, breaks = "equal", axes=TRUE)
> names(x2) = names(y)
> all.equal(x2, y) # yes?
[1] TRUE
> 
> if (FALSE) { # FIXME: to be removed when sf >= 0.7-4 is on CRAN
+ # does gdal reproduce with stars template object?
+ (x2 = st_warp(x, y, use_gdal = TRUE))
+ 
+ # does gdal reproduce what stars does, default cell size?
+ (x2 = st_warp(x, crs = st_crs(x), use_gdal = FALSE))
+ (y = st_warp(x, x2, use_gdal = TRUE, debug = FALSE))
+ 
+ # try with multiple bands:
+ tif = system.file("tif/L7_ETMs.tif", package = "stars")
+ (x1 = read_stars(tif))
+ (x1p = read_stars(tif, proxy = TRUE))
+ (x1a = st_warp(x1, crs = st_crs(4326)))
+ (x1b = st_warp(x1, x1p, use_gdal = TRUE))
+ 
+ # does gdal reproduce what stars does? Smaller grid:
+ (x2 = st_warp(x, crs = st_crs(x), use_gdal = FALSE, cellsize = 3))
+ # x2 = x2[,2:43,2:43]
+ plot(x2, breaks = "equal", axes=TRUE, reset = FALSE)
+ plot(st_as_sfc(st_bbox(x2)), add = TRUE, col = NA, border = 'red')
+ ### doesn't work: FIXME: check with more recent GDAL:
+ #(y = st_warp(x, x2, use_gdal = TRUE, debug = FALSE))
+ #plot(y, breaks = "equal")
+ #names(x2) = names(y)
+ #all.equal(x2, y) 
+ }
> 
> proc.time()
   user  system elapsed 
  0.841   0.057   0.890 
