rbindlist() with list of sf objects doesn't combine different geometries
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start by running the supplied R example with data.table::rbindlist() and the split sf objects. Inspect the rbindlist() handling of class attributes on the geometry column and compare it with do.call(rbind, st.split). Done means the reported differing-geometry case combines without the current class-mismatch error while preserving the expected result.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I've check the NEWS/issues/stack overflow but not seen any mentions of rbindlist() in connection with this issue.
I want to make use of data.table's amazing speed :) in combining sf dataframes as in this example here, issue #798
However, when different geometries are involved, an error is returned on different class attributes of the geometry column in the sf dataframe. Here is a simple example:
library(sf)
# create a sf data frame with different geometries
st <- st_as_sf(data.frame(
id = 1:2,
geometry = st_as_sfc(c("LINESTRING(10 5, 9 4, 8 3, 7 2, 6 1)",
"MULTILINESTRING ((0 3, 0 4, 1 5, 2 5), (0.2 3, 0.2 4, 1 4.8, 2 4.8), (0 4.4, 0.6 5))"))))
st
# split into list
st.split <- split(st, ~id)
# attempt to recombine with rbindlist() - error
st2.dt <- data.table::rbindlist(st.split)
# Error in data.table::rbindlist(st.split) :
# Class attribute on column 2 of item 2 does not match with column 2 of item 1.
# rbind does work:
st2.rbind <- do.call(rbind, st.split)
st2.rbind
# Is data table checking these classes?
lapply(st.split, function(x) class(x$geometry))
A workaround can be to use st_cast() to unify geometries (eg to LINESTRING here, or more generally GEOMETRYCOLLECTION) but this is not alway practical.
Can this check on classes be changed for sf objects so that different geometries can be combined?
# Output of sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sf_1.0-8
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 rstudioapi_0.14 magrittr_2.0.3 units_0.8-0 tidyselect_1.1.2 R6_2.5.1 rlang_1.0.5
[8] fansi_1.0.3 dplyr_1.0.9 tools_4.2.1 grid_4.2.1 compare_0.2-6 data.table_1.14.2 KernSmooth_2.23-20
[15] utf8_1.2.2 cli_3.3.0 e1071_1.7-11 DBI_1.1.3 class_7.3-20 assertthat_0.2.1 tibble_3.1.8
[22] lifecycle_1.0.1 purrr_0.3.4 vctrs_0.4.1 glue_1.6.2 proxy_0.4-27 compiler_4.2.1 pillar_1.8.1
[29] generics_0.1.3 classInt_0.4-7 pkgconfig_2.0.3
- Ngôn ngữ chính
- R
- Star
- 3.9k
- Fork
- 1.1k
- Merge trung bình
- 14 giờ 4 phút
- Pull request đã merge (30 ngày)
- 4
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Rdatatable/data.table#7853 · 3 bình luận ·
-
internals
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Rdatatable/data.table#6938 · 1 bình luận ·
-
encoding fread
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Rdatatable/data.table#5179 · 8 bình luận ·
-
documentation programming
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Rdatatable/data.table#3199 · 3 bình luận ·
Tất cả issue của Rdatatable/data.table
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
r-lib/pkgdepends#485 · 3 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
beginners blocker
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
enviPathR Đang mởBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
Bioconductor/BiocContributions#207 · 6 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
datacarpentry/semester-biology#1255 ·