星星对象的 Bbox 小于星星对象本身?

Bbox of stars object smaller than stars object itself?

当我绘制“星星”对象的边界框时,边界框小于对象本身。可能我的代码有错误,但我不知道在哪里...

事实上,两个问题合二为一,第二个是意想不到的,因为它是在我准备我的 reprex 时发生的(见下文):虽然 bbox 绘制在 'Plots pane' 中,但它没有出现在来自 REPREX 的图像。 add=TRUE 可能有问题...

如果有人能帮我解决这两个问题,我将不胜感激。

这是 REPREX:

library(stars)
#> Le chargement a nécessité le package : abind
#> Le chargement a nécessité le package : sf
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(sf)

tif <- system.file("tif/L7_ETMs.tif", package = "stars")
tif <- read_stars(tif)

# 1 - plotting the first band of stars object
plot(tif[,,,1], main = NULL, key.pos = NULL)
#> downsample set to c(0,0,1)

# 2 - plotting the bbox of the raster
plot(st_geometry(st_sfc(st_polygon(list(cbind(c(st_bbox(tif)[[1]],
                                                st_bbox(tif)[[3]],
                                                st_bbox(tif)[[3]],
                                                st_bbox(tif)[[1]],
                                                st_bbox(tif)[[1]]),
                                              c(st_bbox(tif)[[2]],
                                                st_bbox(tif)[[2]],
                                                st_bbox(tif)[[4]],
                                                st_bbox(tif)[[4]],
                                                st_bbox(tif)[[2]])))),
                        crs = st_crs(tif))),
     border = "red", lwd = 5, add = TRUE)

reprex package (v2.0.0)

于 2021-08-03 创建

我认为你只需要改变绘图的顺序,你还可以进一步简化你的 bbox 构造:

library(stars)
library(sf)
tif <- system.file("tif/L7_ETMs.tif", package = "stars")
tif <- read_stars(tif)
plot(st_as_sfc(st_bbox(tif)), border = 'red', lwd = 5)
plot(tif[,,,1], main = NULL, key.pos = NULL, add = TRUE)

我经历了同样的头部划痕,但绘图顺序颠倒了。