提取多边形和中心作为 sf 中的列

Extract polygon and center as column in sf

我有一个具有这种结构的 sf 样式数据框:

Classes ‘sf’ and 'data.frame':  1672 obs. of  3 variables:
 '$ grid.100:sfc_POLYGON of length 1672; first list element: List of 1
 ' ..$ : num [1:5, 1:2] 542829 543129 543129 542829 542829 ...
  ..- attr(*, "class")= chr  "XY" "POLYGON" "sfg"
' $ id      : int  1 2 3 4 5 6 7 8 9 10 ...
' $ count   : int  0 0 0 0 0 0 0 0 1 0 ...
 - attr(*, "sf_column")= chr "grid.100"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA
  ..- attr(*, "names")= chr  "id" "count"

我想要做的是从 POLYGON 特征中提取单独的坐标,因此多边形的每一边都是它自己的数据框中的列。

有什么想法吗?

我想通了,我想:

grid.sff <- grid.sf %>%
  dplyr::mutate(latt = sf::st_coordinates(grid.sf$center)[,1]) %>%
  dplyr::mutate(lonn = sf::st_coordinates(grid.sf$center)[,2])