Learn R Programming

RGISTools (version 0.9.7)

genSaveTSRData: Saves a time series of images as an RData

Description

genSaveTSRData imports a time series of images from a folder (GTiff format), builds a RasterStack and saves it in an RData.

Usage

genSaveTSRData(src, AppRoot = NULL, ts.name = "TS.Name",
  startDate = NULL, endDate = NULL, dextent = FALSE,
  recursive = FALSE)

Arguments

src

path to the folder where the time series of images is located.

AppRoot

the path where the RData is saved.

ts.name

the name of the RasterStack in the RData.

startDate

a Date class object with the starting date of the study period.

endDate

a Date class object with the ending date of the study period.

dextent

a logical argument. If TRUE, the function expands the extent of the RasterStack to embrace the extents of all GTiff images.

recursive

logical argument. If TRUE, reads folders recursively, searching for GTiff images.

Value

if AppRoot is not asigned a RasterStack with the time series in src folder.

Details

The function reads all the images inside the folder specified in src. Images files must be GTiffs. The src can take the path created by other functions of this package, such as senMosaic, modMosaic, senFolderToVar, etc. The images are imported into `R' to build a RasterStack. The name of the RasterStack is specified in ts.name. The RasterStack is saved in an RData file in the AppRoot directory.

Examples

Run this code
# NOT RUN {
# load a spatial polygon object of Navarre
data(ex.navarre)
# set the download folder
s.start <- Sys.time()
src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)
# download the images
modDownload(product = "MOD09GA",
            startDate = as.Date("30-07-2018", "%d-%m-%Y"),
            endDate = as.Date("06-08-2018", "%d-%m-%Y"),
            username = "username",
            password = "password",
            AppRoot = src,
            extract.tif = TRUE,
            collection = 6,
            extent = ex.navarre)
# set folder path where MOD09GA images will be saved
src1 <- file.path(src,"Modis","MOD09GA")
# set the tif folder path
tif.src <- file.path(src1,"tif")
# mosaic and cut navarre region
modMosaic(tif.src,
          AppRoot = src1,
          out.name = "Navarre",
          extent = ex.navarre)
# change src to navarre folder
src2 <- file.path(src1,"Navarre")
# calculate NDVI from navarre folder
modFolderToVar(src2,
               fun = varNDVI,
               AppRoot = dirname(src2),
               overwrite = TRUE)
# change src TS_sample
src3 <- file.path(dirname(src2),"NDVI")
# create the Rdata
genSaveTSRData(src3, ts.name = "ModisNDVI", AppRoot = src1)
# remove values out of 0-1 range
ModisNDVI.lim <- genLimitRasterRange(ModisNDVI, mn = 0, mx = 1)
# plot the ndvi images
spplot(ModisNDVI.lim)
s.end <- Sys.time()
s.end - s.start
# }

Run the code above in your browser using DataLab