R Under development (unstable) (2024-11-06 r87293 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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) > xy = structure(list(x = c(293253.999046018, 296400.196497684), y = c(9113801.64775462, + 9111328.49619133)), .Names = c("x", "y")) > pts = st_as_sf(data.frame(do.call(cbind, xy)), coords = c("x", "y"), crs = st_crs(x)) > image(x, axes = TRUE) > plot(st_as_sfc(st_bbox(pts)), col = NA, add = TRUE) > > bb = st_bbox(pts) > (xx = x[bb]) stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. L7_ETMs.tif 3 56 73 70.87303 89 255 dimension(s): from to offset delta refsys point x/y x 158 268 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 245 331 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA > image(xx) > plot(st_as_sfc(bb), add = TRUE, col = NA) > st_contains(st_as_sfc(st_bbox(xx)), st_as_sfc(st_bbox(pts))) Sparse geometry binary predicate list of length 1, where the predicate was `contains' 1: 1 > > image(x) > pt = st_point(c(x = 290462.103109179, y = 9114202.32594085)) > buf = st_buffer(st_sfc(pt, crs = st_crs(x)), 1500) > plot(buf, add = TRUE) > > buf = st_sfc(st_polygon(list(st_buffer(pt, 1500)[[1]], st_buffer(pt, 1000)[[1]])), + crs = st_crs(x)) > image(x[buf]) > plot(buf, add = TRUE, col = NA) > image(x[buf,crop=FALSE]) > plot(buf, add = TRUE, col = NA) > > plot(x, rgb = 1:3) > > # #638: > l = st_as_stars(L7_ETMs) > st_bbox(l) |> st_as_sfc() -> bb > (bb + 1e6) |> st_set_crs(st_crs(l)) -> b > st_crop(l, b) stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. NA's L7_ETMs NA NA NA NaN NA NA 737088 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA Warning message: In st_crop.stars(l, b) : st_crop: bounding boxes of x and y do not overlap > st_intersects(b, st_as_sfc(st_bbox(l))) |> as.matrix() [,1] [1,] FALSE > (bb - 1e6) |> st_set_crs(st_crs(l)) -> b > st_crop(l, b) stars object with 3 dimensions and 1 attribute attribute(s): Min. 1st Qu. Median Mean 3rd Qu. Max. NA's L7_ETMs NA NA NA NaN NA NA 737088 dimension(s): from to offset delta refsys point x/y x 1 349 288776 28.5 SIRGAS 2000 / UTM zone 25S FALSE [x] y 1 352 9120761 -28.5 SIRGAS 2000 / UTM zone 25S FALSE [y] band 1 6 NA NA NA NA Warning message: In st_crop.stars(l, b) : st_crop: bounding boxes of x and y do not overlap > > proc.time() user system elapsed 4.76 0.50 5.26