用包含橄榄酸间隔的列表柱的毫无疑问的SF数据框

发布于 2025-01-19 21:29:25 字数 1707 浏览 1 评论 0原文

我从一个名为 polygon_history 的 sf 数据框开始,其中包含以下列:

polygon_id,valid_period,geometry

其中 valid_period 是使用 lubridate 包创建的两个日期之间的间隔。

我将 valid_period 细分为更小的间隔,并通过获取 valid_period 与日期范围列表 (sectionized_periods) 的交集将它们组合在一个列表中,我有兴趣单独分析,代码如下:

sectionized_periods
[1] 2021-09-01 UTC--2021-09-07 UTC 2021-09-07 UTC--2021-10-10 UTC 2021-10-10 UTC--2021-10-24 UTC 2021-10-24 UTC--2021-11-30 UTC

polygon_history %>%
  rowwise %>%
  mutate(period_section = list(c(lubridate::intersect(valid_period,sectionized_periods)))) 

现在我的表有以下列:

polygon_id, valid_period, period_sections, geometry

其中 period_sections 是一个列表列;每行都是 [lubridate] 间隔的列表。

period_sections 中的示例行:

polygon_history$period_section[1]
[[1]]
[1] 2021-09-01 UTC--2021-09-07 UTC 2021-09-07 UTC--2021-10-10 UTC 2021-10-10 UTC--2021-10-24 UTC 2021-10-24 UTC--2021-11-30 UTC

我尝试根据 period_sections 列表列取消嵌套此表,以便为列表的每个元素(每个间隔)保留一行,但是,当我运行下面的代码时,我只得到 period_section 中的数值而不是间隔。我相信这个数值代表间隔的持续时间,但我需要有间隔。

polygon_history <- polygon_history %>%
+     rowwise %>%
+     mutate(PERIOD_SECTION = list(c(lubridate::intersect(VALID_PERIOD,sectionized_periods)))) %>%
+     unnest(PERIOD_SECTION) %>%
+     sf::st_sf() 

polygon_history$PERIOD_SECTION
An object of class "vctrs:::common_class_fallback"
 [1]  518400 2851200 1209600 3196800  518400 2851200 1209600 3196800  518400 2851200 1209600 3196800  518400 2851200 1209600 3196800  518400 2851200
[19] 1209600

感谢任何有关如何解决此问题的见解。谢谢!

I start with an sf dataframe, called polygon_history, with the following columns:

polygon_id,valid_period,geometry

where valid_period is an interval between two dates created using lubridate package.

I subdivided valid_period into smaller intervals and combine them in a list by obtaining the intersection of the valid_period with a list of date ranges (sectionized_periods) that I am interested in analyzing separately, with the code below:

sectionized_periods
[1] 2021-09-01 UTC--2021-09-07 UTC 2021-09-07 UTC--2021-10-10 UTC 2021-10-10 UTC--2021-10-24 UTC 2021-10-24 UTC--2021-11-30 UTC

polygon_history %>%
  rowwise %>%
  mutate(period_section = list(c(lubridate::intersect(valid_period,sectionized_periods)))) 

Now my table has the following columns:

polygon_id, valid_period, period_sections, geometry

where period_sections is a list-column; and every row is a list of [lubridate] intervals.

Example row in period_sections:

polygon_history$period_section[1]
[[1]]
[1] 2021-09-01 UTC--2021-09-07 UTC 2021-09-07 UTC--2021-10-10 UTC 2021-10-10 UTC--2021-10-24 UTC 2021-10-24 UTC--2021-11-30 UTC

I am trying to unnest this table based on the period_section list-column in order to have a row for each element of the list (each interval), however when I run the code below, I only get numeric values in period_section instead of the intervals. I believe this numeric value represents the duration of the interval, but I need to have the interval instead.

polygon_history <- polygon_history %>%
+     rowwise %>%
+     mutate(PERIOD_SECTION = list(c(lubridate::intersect(VALID_PERIOD,sectionized_periods)))) %>%
+     unnest(PERIOD_SECTION) %>%
+     sf::st_sf() 

polygon_history$PERIOD_SECTION
An object of class "vctrs:::common_class_fallback"
 [1]  518400 2851200 1209600 3196800  518400 2851200 1209600 3196800  518400 2851200 1209600 3196800  518400 2851200 1209600 3196800  518400 2851200
[19] 1209600

Appreciate any insights on how to solve this. Thanks!

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

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

发布评论

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

评论(1

本宫微胖 2025-01-26 21:29:25

我能够使用unchop来完成我需要的事情。

 polygon_history <- polygon_history %>%
    +     rowwise %>%
    +     mutate(PERIOD_SECTION = list(c(lubridate::intersect(VALID_PERIOD,sectionized_periods)))) %>%
    +     unchop(PERIOD_SECTION) %>%
    +     sf::st_sf() 

I was able to do what I needed using unchop.

 polygon_history <- polygon_history %>%
    +     rowwise %>%
    +     mutate(PERIOD_SECTION = list(c(lubridate::intersect(VALID_PERIOD,sectionized_periods)))) %>%
    +     unchop(PERIOD_SECTION) %>%
    +     sf::st_sf() 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文