【发布时间】:2018-09-24 19:09:41
【问题描述】:
我有一个具有这种结构的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 特征中提取各个坐标,因此多边形的每一边都是数据框中自己的列。
有什么想法吗?
【问题讨论】:
-
一个 sf 多边形是 X 和 Y 值的矩阵;你有三个。您可以提取它们,例如使用
st_coordinates,但不能将其转换为图形,因为它是点矩阵,而不是边。 -
@alistaire 如果列出的列之一是坐标,即:1 x 和 1 y 坐标的列表,该怎么办?你能把它们转换成列吗?
-
你真的需要制作a reproducible example,尽管这对于科幻来说可能很棘手。使用
nc数据 (nc <- st_read(system.file("shape/nc.shp", package="sf"))) 会更容易。
标签: r geospatial sp sf