【问题标题】:apply a function over a list of raster layers在栅格图层列表上应用函数
【发布时间】:2021-12-10 21:59:10
【问题描述】:

我有一个这样的 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 

我想像这样使用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...

为此,我使用了 lapply:

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

但我收到以下错误:

h(simpleError(msg, call)) 中的错误: 在为函数 'crop' 选择方法时评估参数 'x' 时出错:对象 'x' no encontrado

【问题讨论】:

  • 我觉得你需要Map
  • 如果您创建一个小的可重现示例以及预期的输出,这将更容易提供帮助。了解如何提供reproducible example
  • 你可以做Map(crop, myrasteList, aoi)

标签: r raster sf


【解决方案1】:

当您向函数添加参数时,lapply 的 FUN 参数不起作用。你需要做类似的事情

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多