I have this data in XDR format and I tried to open it using R. This is my data
> 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)
Therefore, I want to export each raster into GeoTiff.
May I need to separate the list? How to do that?
Thank you in advance.
If I have understood your request correctly you only have to:
Please find below a small REPREX to illustrate this.
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
Created on 2021-09-20 by the reprex package (v2.0.1)