获取数据框列中坐标的边界框

发布于 2025-01-20 18:52:26 字数 297 浏览 2 评论 0原文

我有一个包含两列数字类型的数据框。

foo <- data.frame(replicate(2,sample(10.1:15.2,100,rep=TRUE)))

    X1 X2
1 13.1 15.1
2 13.1 11.1
3 13.1 15.1
4 10.1 13.1
5 15.1 11.1
6 13.1 11.1
...

这些数字代表 4326 中的坐标。 X1 是纬度,X2 是经度。我如何获得所有这些坐标的边界框?

I have a dataframe with two columns of type numeric.

foo <- data.frame(replicate(2,sample(10.1:15.2,100,rep=TRUE)))

    X1 X2
1 13.1 15.1
2 13.1 11.1
3 13.1 15.1
4 10.1 13.1
5 15.1 11.1
6 13.1 11.1
...

These numbers represent coordinates in 4326. X1 is latitude, X2 is longitude. How would I get the bounding box for all these coordinates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不乱于心 2025-01-27 18:52:27

使用sfheaders稍微Suxpint略微固定,如果您需要在软件包中使用的轻重量选项。

sfheaders::sf_bbox(foo, x = "X2", y = "X1")

# xmin ymin xmax ymax 
# 10.1 10.1 15.1 15.1 
# attr(,"class")
# [1] "bbox"

但是,如果您在工作流程中使用sf,则纯sf方法很好。

Slightly more succint using sfheaders if you want a light-weight option for using in a package.

sfheaders::sf_bbox(foo, x = "X2", y = "X1")

# xmin ymin xmax ymax 
# 10.1 10.1 15.1 15.1 
# attr(,"class")
# [1] "bbox"

But if you're using sf in your workflow anyway, then the pure sf approach is fine.

赢得她心 2025-01-27 18:52:26

转换为sf并使用st_bbox

library(sf)

foo %>% 
  st_as_sf(coords = c("X2","X1"), crs = 4326) %>% 
  st_bbox()

# xmin ymin xmax ymax 
# 10.1 10.1 15.1 15.1 

Convert to sf and use st_bbox:

library(sf)

foo %>% 
  st_as_sf(coords = c("X2","X1"), crs = 4326) %>% 
  st_bbox()

# xmin ymin xmax ymax 
# 10.1 10.1 15.1 15.1 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文