在R包Terra中按总和合并多个SpatRasters

gblwokeq  于 2023-04-03  发布在  其他
关注(0)|答案(1)|浏览(258)

我有两个SpatRaster,我想合并。当他们合并时,我希望每个像素从两个光栅的值求和。我已经尝试了以下代码,但它不工作。我该怎么做?

abd_projected <- project(abd_Americas, crs, method = "near")
abd2_projected <- project(abd2_Americas, crs, method = "near")

class(abd_projected)
[1] "SpatRaster"
attr(,"package")
[1] "terra"
class(abd2_projected)
[1] "SpatRaster"
attr(,"package")
[1] "terra"

merged_abd <- merge(abd_projected, abd2_projected fun = sum )

Error: unexpected symbol in "merged_abd <- merge(abd_projected, 
abd2_projected fun"

merged_abd <- merge(abd_projected, abd2_projected, FUN = sum )
Error: [sprc] list elements should be 'SpatRaster'
is of class: function

我也试过

mergedABD <- raster::merge(abd_projected, abd2_projected, 
tolerance=0.1)

abdall_projected<- c(abd_projected, abd2_projected)
rsum <- app(abdall_projected, sum)

都不管用
如果有帮助的话,我试图合并的数据是来自ebirdst软件包的物种数据。我想在绘制它们之前合并两个物种丰度空间(栅格)数据集。

fquxozlt

fquxozlt1#

您可以使用mosaic,这样您就可以将"sum"指定为用于计算重叠像素中的像素值的函数。

library(terra)
    
resul <- mosaic(abd_projected, abd2_projected, fun = "sum")

相关问题