我有一个sf
对象列表,我想行绑定它们以创建一个单独的sf
对象。我正在寻找类似于data.table :: rbindlist
的函数,可以高效地堆叠各个对象。
可再现示例的数据:
my_list <- structure(list(structure(list(idhex = 4L, geometry = structure(list(
structure(c(664106.970004623, 6524137.38910266), class = c("XY",
"POINT", "sfg"))), class = c("sfc_POINT", "sfc"), precision = 0, bbox = structure(c(xmin = 664106.970004623,
ymin = 6524137.38910266, xmax = 664106.970004623, ymax = 6524137.38910266
), class = "bbox"), crs = structure(list(epsg = 32633L, proj4string = "+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs"), class = "crs"), n_empty = 0L)), row.names = 1L, class = c("sf",
"data.frame"), sf_column = "geometry", agr = structure(c(idhex = NA_integer_), .Label = c("constant",
"aggregate", "identity"), class = "factor")), structure(list(
idhex = 9, geometry = structure(list(structure(c(665491.220375992,
6525002.7560692), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT",
"sfc"), precision = 0, bbox = structure(c(xmin = 665491.220375992,
ymin = 6525002.7560692, xmax = 665491.220375992, ymax = 6525002.7560692
), class = "bbox"), crs = structure(list(epsg = 32633L, proj4string = "+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs"), class = "crs"), n_empty = 0L)), row.names = 1L, class = c("sf",
"data.frame"), sf_column = "geometry", agr = structure(c(idhex = NA_integer_), .Label = c("constant",
"aggregate", "identity"), class = "factor"))), .Dim = 1:2, .Dimnames = list(
".", NULL))
请注意,data.table
和sf
库目前还不完全兼容。因此,rbindlist
函数返回的对象无法被识别为一个`sf对象。
single_sf <- rbindlist(my_list)
class(single_sf)
sf::st_as_sf(data.table::rbindlist(my_list))
。 - TimSalabimmapedit:::combine_list_of_sf
来实现此功能。值得注意的是,https://github.com/r-spatial/mapedit/issues/46 也值得关注,因为在某个阶段,sf 可能会实现专用的bind_rows_sf
。 - TimSalabim