У меня есть набор данных, который представляет собой список списков векторов координат, разделенных на две группы
geom group
list(list(c(43, 43, 40, 40, 43, 10, 13, 13, 10, 10), list(... 1
list(c(95, 100, 100, 95, 95, -12, -12, -19, -19, -12) 2
Я хотел бы преобразовать его в фрейм данных, который выглядит так:
Longitude Latitude Group
43 10 1
43 13 1
et c.
Для воспроизведения моих данных
structure(list(geom = structure(list(structure(list(list(structure(c(43,
43, 40, 40, 43, 10, 13, 13, 10, 10), .Dim = c(5L, 2L))), list(
structure(c(23, 23, 20, 20, 23, 10, 13, 13, 10, 10), .Dim = c(5L,
2L))), list(structure(c(25, 25, 38, 25, 10, 10.3, 10.3, 10
), .Dim = c(4L, 2L)))), class = c("XY", "MULTIPOLYGON", "sfg"
)), structure(list(structure(c(95, 100, 100, 95, 95, -12, -12,
-19, -19, -12), .Dim = c(5L, 2L))), class = c("XY", "POLYGON",
"sfg"))), n_empty = 0L, precision = 0, crs = structure(list(input = "EPSG:4326",
wkt = "GEOGCS[\"WGS 84\",\n DATUM[\"WGS_1984\",\n SPHEROID[\"WGS
84\",6378137,298.257223563,\n AUTHORITY[\"EPSG\",\"7030\"]],\n
AUTHORITY[\"EPSG\",\"6326\"]],\n PRIMEM[\"Greenwich\",0,\n
AUTHORITY[\"EPSG\",\"8901\"]],\n UNIT[\"degree\",0.0174532925199433,\n
AUTHORITY[\"EPSG\",\"9122\"]],\n AUTHORITY[\"EPSG\",\"4326\"]]"), class = "crs"), class =
c("sfc_GEOMETRY",
"sfc"), bbox = structure(c(xmin = 20, ymin = -19, xmax = 100,
ymax = 13), class = "bbox"), classes = c("MULTIPOLYGON", "POLYGON"
)), group = 1:2), row.names = 1:2, sf_column = "geom", agr = structure(c(group =
NA_integer_), class = "factor", .Label = c("constant",
"aggregate", "identity")), class = c("sf", "data.frame"))
Пример данных, разделенных более чем на две группы, в этом случае данные разделены на три группы :
structure(list(geom =
structure(list(structure(list(list(structure(c(43,
43, 40, 40, 43, 10, 13, 13, 10, 10), .Dim = c(5L, 2L))), list(
structure(c(23, 23, 20, 20, 23, 10, 13, 13, 10, 10), .Dim = c(5L,
2L))), list(structure(c(25, 25, 38, 25, 10, 10.3, 10.3, 10
), .Dim = c(4L, 2L)))), class = c("XY", "MULTIPOLYGON", "sfg"
)), structure(list(structure(c(60, 60, 80, 80, 60, 6, 5.7, 5.7,
6, 6), .Dim = c(5L, 2L))), class = c("XY", "POLYGON", "sfg")),
structure(list(structure(c(95, 100, 100, 95, 95, -12, -12,
-19, -19, -12), .Dim = c(5L, 2L))), class = c("XY", "POLYGON",
"sfg"))), n_empty = 0L, precision = 0, crs = structure(list(
input = "EPSG:4326", wkt = "GEOGCS[\"WGS 84\",\n
DATUM[\"WGS_1984\",\n SPHEROID[\"WGS
84\",6378137,298.257223563,\n
AUTHORITY[\"EPSG\",\"7030\"]],\n
AUTHORITY[\"EPSG\",\"6326\"]],\n PRIMEM[\"Greenwich\",0,\n
AUTHORITY[\"EPSG\",\"8901\"]],\n
UNIT[\"degree\",0.0174532925199433,\n
AUTHORITY[\"EPSG\",\"9122\"]],\n AUTHORITY[\"EPSG\",\"4326\"]]"),
class = "crs"), class = c("sfc_GEOMETRY",
"sfc"), bbox = structure(c(xmin = 20, ymin = -19, xmax = 100,
ymax = 13), class = "bbox"), classes = c("MULTIPOLYGON", "POLYGON",
"POLYGON")), group = 1:3), row.names = c(NA, 3L), sf_column = "geom",
agr = structure(c(group = NA_integer_), class = "factor", .Label =
c("constant",
"aggregate", "identity")), class = c("sf", "data.frame"))