r - Bbox的星星物体小于星星物体本身?
问题描述
当我绘制“星星”对象的 bbox 时,bbox 小于对象本身。我的代码可能有错误,但我不知道在哪里......
事实上,两个问题合二为一,第二个问题出乎意料,因为它发生在我准备我的 reprex 时(见下文):虽然 bbox 绘制在“绘图窗格”中,但它没有出现在来自 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 包于 2021-08-03 创建 (v2.0.0 )
解决方案
我认为您只需要更改绘图顺序,还可以简化 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)
我用相反的绘图顺序经历了同样的头部划伤。
推荐阅读
- python - 对 csv 文件中的列日期/时间数据进行排序
- react-native - React Native Orientation 不监听当前系统自动旋转状态
- c++ - 如何使用Qt删除word中的表格行
- javascript - 如何在 formData 中发送布尔值?
- amazon-lex - AWS Lex AlphaNumeric 内置插槽类型不接受字符串
- reactjs - 反应 TypeScript 错误。创建!没有重载匹配此调用。Overload 1 of 2, '(props: Readonly<{}>): 给出了以下错误
- python - 从 ROS 包导入时出现 ModuleNotFoundError
- matplotlib - 如何在 matplotlib 脚本中再添加一个绘图
- python - 尝试定义 cython 方法会导致 `cdef statement not allowed here` 错误
- node.js - 我可以使用 ApolloClient 订阅 Appsync graphql 吗?