首页 > 解决方案 > 在栅格图层列表上应用函数

问题描述

我有一个像这样的 34 个 RasterLayers 列表:

[[34]]
class      : RasterLayer 
band       : 1  (of  10  bands)
dimensions : 6899, 9663, 66665037  (nrow, ncol, ncell)
resolution : 0.0002694946, 0.0002694946  (x, y)
extent     : -6.685352, -4.081226, 39.39795, 41.2572  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : D:/TFM/Imagenes/Imagenes_sinClip/2017.tif 
names      : X2017 

我想使用这样的裁剪列表的所有 RasterLayers simple feature

> aoi
Simple feature collection with 1 feature and 2 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -6.571744 ymin: 39.44875 xmax: -4.10362 ymax: 41.22031
Geodetic CRS:  WGS 84
  Id     area                       geometry
1  0 29488.98 POLYGON ((-6.122013 41.2203...

为此,我使用了 lapply:

crop <- lapply(x = myrasterList, y = aoi, FUN = crop(x, y))

但我收到以下错误:

h(simpleError(msg, call)) 中的错误:在为函数“crop”选择方法时评估参数“x”时出错:对象“x”没有冲突

标签: rrastersf

解决方案


lapply当您向函数添加参数时,FUN 参数的工作方式并非如此。你需要做类似的事情

crop <- lapply(myrasterList, y = aoi, FUN = function(i) crop(i, y))

推荐阅读