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)) > 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 x/y x 1 20 1841002 1.5 WGS 84 / UTM zone 11N TRUE [x] y 1 20 1144003 -1.5 WGS 84 / UTM zone 11N TRUE [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 refsys point geometry 1 100 WGS 84 FALSE band 1 3 NA NA values geometry POLYGON ((-34.91617 -7.94...,...,POLYGON ((-34.91385 -7.95... 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 refsys point geometry 1 100 WGS 84 FALSE band 1 3 NA NA values geometry POLYGON ((-34.91617 -7.94...,...,POLYGON ((-34.91385 -7.95... 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.04 0.20 1.23