Learn R Programming

MODIS (version 1.2.11)

extractDate: Extract Dates from (MODIS) Files

Description

This function helps to extract dates from a vector of files.

Usage

extractDate(files, pos1, pos2, asDate = FALSE, format = "%Y%j")

Value

A list with the following entries: 'inputLayerDates', 'pos1', 'pos2', 'asDate' and, optionally, 'format'. If asDate = FALSE (default), 'inputLayerDates' are represented as character, else as Date.

Arguments

files

A character vector of filenames from which to extract dates. Alternatively, a Raster* with date information in its raster::names().

pos1, pos2

Start and end of date string in 'files' as integer. If missing, attempts to retrieve positions from a look-up table provided that 'files' comply with the MODIS standard naming convention.

asDate

logical. If TRUE, the result is converted to a Date object.

format

character, date format. Used only if asDate = TRUE. Defaults to MODIS date style (i.e., "\%Y\%j" for year and Julian day). See strptime() for modifications.

Author

Matteo Mattiuzzi

Examples

Run this code
# example on HDF files
files <- c("MOD13Q1.A2010209.h18v03.005.2010239071130.hdf",
           "MOD13Q1.A2010225.h18v03.005.2010254043849.hdf")
extractDate(files)
extractDate(files, asDate = TRUE)

# on any other file 
files <- c("Myfile_20010101.XXX", "Myfile_20010115.XXX", "Myfile_20010204.XXX")
extractDate(files, pos1 = 8, pos2 = 15)
extractDate(files, pos1 = 8, pos2 = 15, asDate = TRUE, format = "%Y%m%d")
 

Run the code above in your browser using DataLab