View source: R/modExtractHDF.R
| modExtractHDF | R Documentation | 
modExtractHDF converts the original format of MODIS images (hierarchical
data format or HDF) into GTiffs (one file for each layer).
modExtractHDF( filesHDF, AppRoot, overwrite = FALSE, bFilter = NULL, rm.band = NULL, region = NULL, verbose = FALSE, ... )
| filesHDF | the full path where the HDF files are located. | 
| AppRoot | the directory where the extracted images are saved. | 
| overwrite | logical argument. If  | 
| 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  | 
| verbose | logical argument. If  | 
| ... | arguments for nested functions. 
 | 
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.
## 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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.