首页 > 解决方案 > 将 `st_bbox()` 的结果转换为其他 CRS

问题描述

有没有一种简单的方法可以将简单特征(sf对象)的边界转换为另一个 CRS?

函数的结果st_bbox()是 class bbox。无法将st_transform()其转换为另一个 CRS。

我正在使用基于计算的边界框EPSG: 28992

sf::st_bbox(xmin = 187470, xmax =194587, 
            ymin = 409753, ymax = 412715,  
            crs = st_crs(28992))

现在我想把这个盒子改造成EPSG:4326

标签: rtransformgeospatialsf

解决方案


对象有一个st_as_sfc方法bbox,所以我们可以bbox像这样转换:

library(sf)

bb = sf::st_bbox(c(xmin = 187470, xmax =194587, 
                   ymin = 409753, ymax = 412715),  
                 crs = st_crs(28992))

bb_ll = st_bbox(
  st_transform(
    st_as_sfc(bb), 
    4326
  )
)

# or pipey
library(magrittr)

bb_ll = bb %>%
  st_as_sfc() %>%
  st_transform(crs = 4326) %>%
  st_bbox()

bb_ll

    xmin      ymin      xmax      ymax 
5.856639 51.675176  5.959866 51.702257

推荐阅读