从数据框列表中创建空间多边形数据框列表

时间:2014-10-22 09:50:08

标签: r dataframe spatial-data-frame

我想从数据框列表中创建一个空间多边形数据框列表。空间多边形列表称为list_sp_Tanzania,数据框列表称为list_df_Tanzania_Modis500。每个列表包含61个对象,每个对象包含多个多边形。

str(list_df_Tanzania_Modis500)
$ :'data.frame':    30 obs. of  11 variables:
  ..$ ID        : int [1:30] 296 298 321 323 324 330 331 361 419 453 ...
  ..$ LU_1990   : int [1:30] 11 11 11 11 11 11 11 11 11 11 ...
  ..$ LU_2000   : num [1:30] 12 12 12 12 12 12 12 12 12 12 ...
  ..$ CHLU_90_00: chr [1:30] "1112" "1112" "1112" "1112" ...
  ..$ LU_2005   : num [1:30] 12 12 12 12 12 12 12 12 12 15 ...
  ..$ CHLU_00_05: chr [1:30] "1212" "1212" "1212" "1212" ...
  ..$ Tile      : Factor w/ 1 level "S11_E039": 1 1 1 1 1 1 1 1 1 1 ...
  ..$ UNIQ_ID   : Factor w/ 30 levels "S11_E039_296",..: 1 2 3 4 5 6 7 8 9 10 ...
  ..$ AREA      : num [1:30] 219337 347133 393961 181875 105137 ...
  ..$ Sour_90_00: chr [1:30] "Modis500_2000" "Modis500_2000" "Modis500_2000" "Modis500_2000" ...
  ..$ Sour_00_05: chr [1:30] "Modis500_2005" "Modis500_2005" "Modis500_2005" "Modis500_2005" ...

str(list_sp_Tanzania)
[[61]]
class       : SpatialPolygons 
features    : 30 
extent      : 38.95413, 39.04577, -11.04522, -10.95469  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0

很遗憾,我无法使用dput提供数据,因为它们是s4 objects,我找不到类似的示例。希望有人能以某种方式帮助我。

1 个答案:

答案 0 :(得分:2)

这是解决方案。

fun <- function(x, y) {
  SpatialPolygonsDataFrame(x, y, match.ID = F)
}

list_Spdf_Tanzania_Modis500 <- mapply(FUN = fun, 
                                      x = list_sp_Tanzania, 
                                      y = list_df_Tanzania_Modis500)
相关问题