正如@spacedman 所指出的,一个坐标系中的矩形可能不是另一个坐标系中的矩形。有些坐标系比其他坐标系更弯曲!
为了更安全地变换边界框,您可以使用 st_make_grid(n = whatever) 添加顶点。
# pipey code to show the steps clearly
library(sf)
library(dplyr)
bb_better_reproj = bb_orig %>%
st_make_grid(n=10) %>% #this also makes it into a polygon
st_transform(crs = 4326) %>%
st_bbox()
这不是 100% 安全的,但比仅转换矩形多边形(仅转换角顶点,中间没有任何东西)要好。太多的网格顶点真的很慢。我发现 ~10-20 在大多数情况下效果很好。
一个例子(使用与 OP 不同的坐标参考系统 (CRS) 来说明):
library(sf)
library(dplyr)
bb_orig = st_bbox(c(xmin = 40, xmax =-40,
ymin = 45, ymax = 55),
crs = st_crs(4326)) #lag/long
new_crs = 3995 # arctic polar stereographic
bb_simple_reproj = bb_orig %>%
st_as_sfc() %>%
st_transform(crs=new_crs) %>%
st_bbox
bb_better_reproj = bb_orig %>%
st_make_grid(n=10) %>%
st_transform(crs = new_crs) %>%
st_bbox()
# 100 random points inside the original bounding box (grey)
sample_from_bb_orig = st_sample(st_as_sfc(bb_orig), 1000) %>%
st_transform(new_crs)
plot(st_geometry(sample_from_bb_orig), col="grey")
# if the bbox was only transformed as simple rectangle we would get (red):
# red points indicate those missed by the simple bbox reprojection -- note that many are missed!
plot(st_geometry(st_as_sfc(bb_simple_reproj)), border="red", add=TRUE)
plot(st_difference(sample_from_bb_orig, st_as_sfc(bb_simple_reproj)) , col="red", add=TRUE)
# using 'better' repojection, with more vertices added (blue)
# blue points indicate those missed by the simple bbox reprojection
plot(st_geometry(st_as_sfc(bb_better_reproj)), border="blue", add=TRUE)
plot(st_difference(sample_from_bb_orig, st_as_sfc(bb_better_reproj)) , col="blue", pch="x", add=TRUE)