Currently list-columns are treated like vectors - each 'row' is expanded
library(sfheaders)
df <- data.frame(
id = c(1,1,1,2,2)
, x = 1:5
, y = 1:5
)
sf <- sf_linestring(obj = df, linestring_id = "id")
sf$l <- list(c(1,2,3),c(4,5))
sf
# id geometry l
# 1 1 1, 2, 3, 1, 2, 3 1, 2, 3
# 2 2 4, 5, 4, 5 4, 5
sf_to_df( sf, fill = T )
# id l sfg_id linestring_id x y
# 1 1 1, 2, 3 1 1 1 1
# 2 1 1, 2, 3 1 1 2 2
# 3 1 1, 2, 3 1 1 3 3
# 4 2 4, 5 2 2 4 4
# 5 2 4, 5 2 2 5 5
But it may be necessary, especially for mapdeck, to have a list-column of values which apply to each coordinate, like a colouring value. In which case they should be un-listed like the coordinates, to give
I think the easiest way to make this work is to have an unlist = c() argument, where you specify the columns you want to unlist.
The un-listing is then done at the last step in sf_to_df() (in C++)
TODO
[x] unlist_list function in sf_to_df()
[x] error if the length of list doesn't equal res.nrow()
Currently list-columns are treated like vectors - each 'row' is expanded
But it may be necessary, especially for mapdeck, to have a list-column of values which apply to each coordinate, like a colouring value. In which case they should be un-listed like the coordinates, to give
I think the easiest way to make this work is to have an
unlist = c()
argument, where you specify the columns you want to unlist. The un-listing is then done at the last step insf_to_df()
(in C++)TODO
unlist_list
function insf_to_df()
res.nrow()