[英]apply a function over a list of raster layers
I have a list of 34 RasterLayers like this:我有一个像这样的 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
I want to crop all the RasterLayers of the list using a simple feature
like this:我想使用这样的
simple feature
裁剪列表的所有 RasterLayers:
> 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...
To do that, I used lapply:为此,我使用了 lapply:
crop <- lapply(x = myrasterList, y = aoi, FUN = crop(x, y))
But I get the following error:但我收到以下错误:
Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'crop': objeto 'x' no encontrado
h(simpleError(msg, call)) 中的错误:在选择函数 'crop' 的方法时评估参数 'x' 时出错:objeto 'x' no encontrado
The FUN argument of lapply
does not work like that when you add arguments to the function.当您向函数添加参数时,
lapply
的 FUN 参数不会像那样工作。 You need to do something like你需要做类似的事情
crop <- lapply(myrasterList, y = aoi, FUN = function(i) crop(i, y))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.