gpt4 book ai didi

R:光栅列表中的光栅马赛克?

转载 作者:行者123 更新时间:2023-12-02 06:16:03 26 4
gpt4 key购买 nike

我正在这里的帖子中工作:How can I create raster mosaic using list of rasters?使用栅格列表创建栅格马赛克。 fmark 给出的答案中的示例运行得很好,但是当我使用自己的数据按照步骤操作时,出现错误。不确定我哪里出错了,非常感谢任何帮助!

R version 2.15.3 (2013-03-01)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] raster_2.2-12 rgdal_0.8-10 sp_1.0-14
loaded via a namespace (and not attached):
[1] grid_2.15.3 lattice_0.20-15 tools_2.15.3

我使用了 How to iterate over a list preserving the format of the results? 中的函数生成我的栅格列表。

ListRasters <- function(list_names) {
raster_list <- list() # initialise the list of rasters
for (i in 1:(length(list_names))){
grd_name <- list_names[i] # list_names contains all the names of the images in .grd format
raster_file <- raster(grd_name)
}
raster_list <- append(raster_list, raster_file) # update raster_list at each iteration
}

然后我生成列表名称并从中创建光栅列表。

wgs84.tif.list <- list.files(path=mod.dir, pattern=glob2rx("*_wgs84.tif"), full.names=T,recursive=F)

list_names <- NULL
for (i in 1:length(wgs84.tif.list)) {
list_names <- c(list_names, wgs84.tif.list[i])
}

raster.list <-sapply(list_names, FUN = ListRasters)

raster.list$fun <- mean
mos <- do.call(mosaic, raster.list)

这是我得到的错误:

Error in function (classes, fdef, mtable) : unable to find an inherited method for function 'mosaic' for signature '"missing", "missing"'

我的 raster.list 像这样开始(它包含 11 个栅格):

 $`/import/c/w/kbennett/MODSCAG/snow-dav.jpl.nasa.gov/modscag-historic/2002/091/MOD09GA.A2002091.h08v03.005.2007124035032snow_fraction_wgs84.tif`
class : RasterLayer
dimensions : 2400, 2400, 5760000 (nrow, ncol, ncell)
resolution : 463.3127, 463.3127 (x, y)
extent : -11119737, -10007786, 5559984, 6671935 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : /import/c/w/kbennett/MODSCAG/snow-dav.jpl.nasa.gov/modscag-historic/2002/091/MOD09GA.A2002091.h08v03.005.2007124035032snow_fraction_wgs84.tif
names : MOD09GA.A2002091.h08v03.005.2007124035032snow_fraction_wgs84
values : 0, 255 (min, max)

最佳答案

我的栅格命名不正确。为了纠正这个问题,在调用 fun 之前运行:

names(rasters.list) <- NULL

然后:

raster.list$fun <- mean
mos <- do.call(mosaic, raster.list)

关于R:光栅列表中的光栅马赛克?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22109774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com