Как связать вместе sf объекты - PullRequest
0 голосов
/ 25 апреля 2020

У меня есть список POLYGON, и я хотел бы создать тиббл с одним многоугольником столбца geomtry.

my_list <- list(structure(list(structure(list(structure(c(1046881.53939377, 
1049327.5242989, 1049327.5242989, 1046881.53939377, 1046881.53939377, 
5704036.79875299, 5704036.79875299, 5706482.78365812, 5706482.78365812, 
5704036.79875299), .Dim = c(5L, 2L))), class = c("XY", "POLYGON", 
"sfg"))), class = c("sfc_POLYGON", "sfc"), precision = 0, bbox = structure(c(xmin = 1046881.53939377, 
ymin = 5704036.79875299, xmax = 1049327.5242989, ymax = 5706482.78365812
), class = "bbox"), crs = structure(list(epsg = 3857L, proj4string = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"), class = "crs"), n_empty = 0L), 
    structure(list(structure(list(structure(c(1044435.55448865, 
    1046881.53939377, 1046881.53939377, 1044435.55448865, 1044435.55448865, 
    5706482.78365812, 5706482.78365812, 5708928.76856324, 5708928.76856324, 
    5706482.78365812), .Dim = c(5L, 2L))), class = c("XY", "POLYGON", 
    "sfg"))), class = c("sfc_POLYGON", "sfc"), precision = 0, bbox = structure(c(xmin = 1044435.55448865, 
    ymin = 5706482.78365812, xmax = 1046881.53939377, ymax = 5708928.76856324
    ), class = "bbox"), crs = structure(list(epsg = 3857L, proj4string = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"), class = "crs"), n_empty = 0L))

Я попытался

tibble(result = do.call(rbind, muylist[1:2]))
# A tibble: 2 x 1
result[,1]
  <list>    
1 <XY>      
2 <XY>   

Я хотел бы :

 result[,1]
      <list>    
    1 <POLYGON [m]>
    2 <POLYGON [m]>

1 Ответ

1 голос
/ 25 апреля 2020
library(sf)

result <- do.call(rbind, lapply(my_list, st_sf))

result[,1]

Simple feature collection with 2 features and 0 fields
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 1044436 ymin: 5704037 xmax: 1049328 ymax: 5708929
CRS:            EPSG:3857
                          X..i..
1 POLYGON ((1046882 5704037, ...
2 POLYGON ((1044436 5706483, ...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...