RGISTools (version 1.0.2)

modExtractHDF: Convert an HDF file into a set of GTiff files

Description

modExtractHDF converts the original format of MODIS images (hierarchical data format or HDF) into GTiffs (one file for each layer).

Usage

modExtractHDF(
  filesHDF,
  AppRoot,
  overwrite = FALSE,
  bFilter = NULL,
  rm.band = NULL,
  region = NULL,
  verbose = FALSE,
  ...
)

Arguments

filesHDF

the full path where the HDF files are located.

AppRoot

the directory where the extracted images are saved.

overwrite

logical argument. If TRUE, overwrites the existing images with the same name.

bFilter

a vector containing the names of the bands to extract.

rm.band

a vector containing the names of the bands excluded from the extraction.

region

a Spatial*, projected raster*, or sf* class object defining the area of interest for image masking.

verbose

logical argument. If TRUE, the function prints the running steps and warnings.

...

arguments for nested functions.

  • dates a vector with the capturing dates being considered for downloading.

Details

HDF files cannot be directly loaded into `R', so they must be converted into GTiffs. To acomplish this task, the function modExtractHDF borrows the gdalwarp and gdal_translate functions from the `gdalUtils' package. Further details about these functions can be found in the corresponding package manual. `GDAL' and `gdalUtils' must be properly installed to use modExtractHDF. GTiffs can be loaded in `R' using the `raster' package.

Examples

Run this code
# NOT RUN {
# load a spatial polygon object of Navarre
data(ex.navarre)

wdir <- file.path(tempdir(),"Path_for_downloading_folder")
print(wdir)
wdir.mod <- file.path(wdir, "Modis","MOD11A1")
sres <- modSearch(product = "MOD11A1",
                  startDate = as.Date("01-01-2011", "%d-%m-%Y"),
                  endDate = as.Date("01-01-2011", "%d-%m-%Y"),
                  collection = 6,
                  extent = ex.navarre)
                      
# download the images of the list
wdir.mod <- file.path(wdir, "Modis", "MOD11A1")
modDownload(searchres = sres, 
            username = "username", 
            password = "password",
            AppRoot = wdir.mod)

wdir.mod.tif<-file.path(wdir.mod,"tif")
wdir.mod.hdf <- file.path(wdir.mod, "hdf")

# extract the first image
files.mod.hdf <- list.files(wdir.mod.hdf, 
                        full.names = TRUE, 
                        pattern = "\\.hdf$")
files.mod.hdf.1 <- files.mod.hdf[1]
modExtractHDF(filesHDF = files.mod.hdf.1,
              AppRoot = wdir.mod.tif)
# }

Run the code above in your browser using DataLab