如何将栅格列表提取到 R 中的单独栅格中

How to extract lists of raster into separate raster in R

我有 XDR 格式的数据,我尝试使用 R 打开它。 这是我的数据

>  unlist(MCD12Q1.wgs84.ras.01L)
[[1]]
class      : RasterLayer 
dimensions : 276, 199, 54924  (nrow, ncol, ncell)
resolution : 0.00702, 0.00417  (x, y)
extent     : 136.2091, 137.6061, 34.60728, 35.7582  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : memory
names      : layer 
values     : 1, 17  (min, max)


[[2]]
class      : RasterLayer 
dimensions : 276, 199, 54924  (nrow, ncol, ncell)
resolution : 0.00702, 0.00417  (x, y)
extent     : 136.2091, 137.6061, 34.60728, 35.7582  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : memory
names      : layer 
values     : 1, 17  (min, max)


[[3]]
class      : RasterLayer 
dimensions : 276, 199, 54924  (nrow, ncol, ncell)
resolution : 0.00702, 0.00417  (x, y)
extent     : 136.2091, 137.6061, 34.60728, 35.7582  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : memory
names      : layer 
values     : 1, 17  (min, max)

因此,我想将每个栅格导出到 GeoTiff 中。

我需要分开列表吗?怎么做?

提前致谢。

如果我正确理解了您的要求,您只需:

  1. 堆叠您的栅格列表,
  2. 写入每个栅格,在函数 writeRaster() 中指定参数“bylayer”。

请在下面找到一个小的 REPREX 来说明这一点。

REPREX:

library(raster)
#> Le chargement a nécessité le package : sp

# Creating a list of three rasters (same as your object "MCD12Q1.wgs84.ras.01L".)
r1 <- raster(ncols = 3, nrows = 3)
(values(r1) <- seq(length(r1)))
#> [1] 1 2 3 4 5 6 7 8 9
r2 <- r1
r3 <- r1

r_list <- list(r1, r2, r3)
r_list
#> [[1]]
#> class      : RasterLayer 
#> dimensions : 3, 3, 9  (nrow, ncol, ncell)
#> resolution : 120, 60  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> source     : memory
#> names      : layer 
#> values     : 1, 9  (min, max)
#> 
#> 
#> [[2]]
#> class      : RasterLayer 
#> dimensions : 3, 3, 9  (nrow, ncol, ncell)
#> resolution : 120, 60  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> source     : memory
#> names      : layer 
#> values     : 1, 9  (min, max)
#> 
#> 
#> [[3]]
#> class      : RasterLayer 
#> dimensions : 3, 3, 9  (nrow, ncol, ncell)
#> resolution : 120, 60  (x, y)
#> extent     : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> source     : memory
#> names      : layer 
#> values     : 1, 9  (min, max)


# Stacking your list of three rasters
r_stack <- stack(r_list)

# Writing each raster independently in your working directory
writeRaster(r_stack, "raster.tif", bylayer = TRUE, suffix = 1:nlayers(r_stack))

# This will give you three GeoTiff files named:
# - raster_1.tif
# - raster_2.tif
# - raster_3.tif

reprex package (v2.0.1)

于 2021-09-20 创建