0
我已经创建了这个脚本来计算两个常量rc_Mod2000_LC,y = S01_E031_FC的一个输出。如何用多个shapefile数据集创建for循环函数?
# Extract LUC in Mod2000
LU_S01_E031_FC_Mod2000 <- extract(x=rc_Mod2000_LC, y=S01_E031_FC)
maj <- function(x){
y <- as.numeric(names(which.max(table(x))))
return(y)
}
LU_S01_E031_FC_Mod2000 <- extract(x=rc_Mod2000_LC, y=S01_E031_FC, fun=maj)
colnames (LU_S01_E031_FC_Mod2000) <- c("LU_2000")
现在,我想创建一个for循环函数,其中rc_Mod2000_LC是一个常数(光栅),但其中S01_E031_FC是一个变量(shape文件)。 rc_Mod2000_LC是全球土地覆盖地图,S01_E031_FC是地块。我有61个shapefile的列表。
[[1]]
class : SpatialPolygonsDataFrame
features : 16
extent : 30.95493, 31.02964, -1.040257, -0.9624111 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
variables : 16
names : ID, Area_ORG, LU_1990, LU_2000, CHLU_90_00, LU_2005, CHLU_00_05, Tile, UNIQ_ID, AREA, D_90_00, D_00_05, Sour_90_00, Sour_00_05, Conf_90_00, ...
min values : 1139, 10.44, 11, 11, 1111, 0, 1112, S01_E031, S01_E031_1139, 90260.9, 100, 200, GLSE_00, GLSE_05, 3, ...
max values : 935, 8.97, 11, 12, 1112, 0, 1230, S01_E031, S01_E031_935, 1029736.2, 520, 520, GLSE_00, GLSE_05, 3, ...
[[2]]
class : SpatialPolygonsDataFrame
features : 2
extent : 30.95484, 30.99854, -2.022452, -1.971676 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
variables : 16
names : ID, Area_ORG, LU_1990, LU_2000, CHLU_90_00, LU_2005, CHLU_00_05, Tile, UNIQ_ID, AREA, D_90_00, D_00_05, Sour_90_00, Sour_00_05, Conf_90_00, ...
min values : 466, 0.06, 11, 11, 1111, 0, 1130, S02_E031, S02_E031_466, 603.7435, 100, 520, GLSE_00, GE_06, 3, ...
max values : 975, 3.15, 11, 11, 1111, 0, 1130, S02_E031, S02_E031_975, 31698.1260, 100, 520, GLSE_00, GLSE_05, 3, ...
因此我想x = rc_Mod2000_LC和y = shapefile的列表。希望有人能帮助我,让我知道你是否需要澄清。
所以,extract_shape是一个函数。所以我应该写extract_shape <-function(y = shape,x = rc_Mod2000_LC),对吧?而y = shape应该是list_shapes还是不是?谢谢 – 2014-10-16 11:38:41
没有“y”是列表名称的元素... – agstudy 2014-10-16 12:41:14
我已更新我的问题,因为最终您的答案似乎无法解决。 – 2014-10-16 14:10:43