genFilterStack: Subset a RasterStack given a range of dates

Description Usage Arguments Details Value Examples

View source: R/genFilterStack.R

Description

genFilterStack filters the RasterLayers within a range of dates.

Usage

1

Arguments

r

the RasterStack to be filtered.

...

arguments for nested functions:

  • 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.

  • AppRoot the path where the RData will be saved.

Details

This is a helper function used by other functions in this package.

Value

a RasterStack with images within the specified dates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# generate random images
img <- matrix(1:16, ncol = 4, byrow = TRUE)
r <- raster(img)
r <- stack(r, r, r, r, r, r)
names(r) <- paste0("RandomImage_201803", 1:6)
# print the names and dates of the random images
print(names(r))
genGetDates(names(r))
# example of filtering the raster stack
r2 <- genFilterStack(r = r,
                     startDate = as.Date("2018-02-02", "%Y-%m-%d"),
                     endDate = as.Date("2018-02-04", "%Y-%m-%d"))
# print the names and the number of layers of the filtered stack
genGetDates(names(r2))
nlayers(r2)

Example output

Loading required package: raster
Loading required package: sp
Loading required package: sf
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
Loading required package: tmap
[1] "RandomImage_2018031" "RandomImage_2018032" "RandomImage_2018033"
[4] "RandomImage_2018034" "RandomImage_2018035" "RandomImage_2018036"
[1] "2018-01-31" "2018-02-01" "2018-02-02" "2018-02-03" "2018-02-04"
[6] "2018-02-05"
[1] "2018-02-02" "2018-02-03" "2018-02-04"
[1] 3

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