RGISTools (version 0.9.7)

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, shp = 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.

shp

the path to shape file of the area of interest in the hard drive.

verbose

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

...

arguments for nested functions.

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)

src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)
src.mod <- file.path(src, "Modis","MOD11A1")
src.mod.hdf <- file.path(src.mod, "hdf")
img.list <- 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,
                      AppRoot = src.mod.hdf)
                      
# download the images of the list
src.mod <- file.path(src, "Modis", "MOD11A1")
modDownSearch(searchres = img.list, 
              username = "username", 
              password = "password",
              AppRoot = src.mod.hdf)

src.tif<-file.path(src.mod,"tif")

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

Run the code above in your browser using DataCamp Workspace