将 `st_bbox()` 的结果转换为其他 CRS [英] Transform result of `st_bbox()` to other CRS

查看:34
本文介绍了将 `st_bbox()` 的结果转换为其他 CRS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a simple way to transform the bounding of a simple feature (sf object) to another CRS?

函数st_bbox() 的结果属于bbox 类.无法使用 st_transform() 将其转换为另一个 CRS.

The result of the function st_bbox() is of class bbox. It is not possible to use st_transform() to transform it to another CRS.

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

I am using a calculated bounding box based EPSG: 28992:

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

现在我想将此框转换为 EPSG:4326

Now I want to transform this box to EPSG:4326

推荐答案

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

There is a st_as_sfc method for bbox objects, so we can transform a bbox like this:

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

这篇关于将 `st_bbox()` 的结果转换为其他 CRS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆