genSaveTSRData: Saves a time series of images as an RData

Description Usage Arguments Details Value Examples

View source: R/genSaveTSRData.R

Description

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

Usage

1
2
3
4
5
6
7
8
9
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.

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.

Value

a RasterStack when the AppRoot argument is not defined. The function does not return anything otherwise.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Not run: 
# load a spatial polygon object of Navarre
data(ex.navarre)
# set the download folder
s.start <- Sys.time()
wdir <- file.path(tempdir(),"Path_for_downloading_folder")
print(wdir)
# download the images
modDownSearch(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 = wdir,
            extract.tif = TRUE,
            collection = 6,
            extent = ex.navarre)
# set folder path where MOD09GA images will be saved
wdir.mod <- file.path(wdir,"Modis","MOD09GA")
# set the tif folder path
wdir.mod.tif <- file.path(wdir.mod,"tif")
# mosaic and cut navarre region
modMosaic(wdir.mod.tif,
          AppRoot = wdir.mod,
          out.name = "Navarre",
          extent = ex.navarre)
# change src to navarre folder
wdir.mod.navarre <- file.path(wdir.mod,"Navarre")
# calculate NDVI from navarre folder
modFolderToVar(wdir.mod.navarre,
               fun = varNDVI,
               AppRoot = dirname(wdir.mod.navarre),
               overwrite = TRUE)
# change src TS_sample
wdir.mod.ndvi <- file.path(dirname(wdir.mod.navarre),"NDVI")
# create the Rdata
tiles.mod.ndvi<-genSaveTSRData(wdir.mod.ndvi, ts.name = "ModisNDVI")
# remove values out of 0-1 range
tiles.mod.ndvi.lim <- clamp(tiles.mod.ndvi,lower=0,upper=1)
# plot the ndvi images
spplot(tiles.mod.ndvi.lim)
s.end <- Sys.time()
s.end - s.start

## End(Not run)

RGISTools documentation built on July 2, 2020, 3:58 a.m.