Learn R Programming

RGISTools (version 0.9.7)

lsDownSearch: Download Landsat-7 or Landsat-8 images from a search list

Description

lsDownSearch downloads the results from ls7Search and ls8Search functions. The images are saved as GTiff files in the AppRoot directory.

Usage

lsDownSearch(searchres, username = NULL, password = NULL, AppRoot,
  lvl = 1, product = c("sr", "source_metadata"), verbose = FALSE,
  raw.rm = FALSE, untar = FALSE, overwrite = FALSE, nattempts = 5,
  ...)

Arguments

searchres

the results from ls7Search or ls8Search.

username

USGS's `EarthExplorer' username.

password

USGS's `EarthExplorer' password.

AppRoot

the download directory.

lvl

a number specifying the processing level. Default value, 1.

product

character vector with the requested Level-2 products. By default c("sr","source_metadata").

verbose

logical argument. If TRUE, the function prints the running steps and warnings.

raw.rm

logical argument. If TRUE, removes the raw images.

untar

logical argument. If TRUE, untars downloaded images.

overwrite

logical argument. If TRUE, overwrites the existing images with the same name.

nattempts

the number of attempts to download an image in case it becomes corrupted.

...

arguments for nested functions.

Details

lsDonwSearch downloads the list of URLs provided by ls7Search or ls8Search as a data.frame. The function requires an USGS's `EarthExplorer' account, which can be obtained here.

The files from `EarthExplorer' are compressed as <U+2018>tar.gz<U+2019>. lsDownSearch decompresses the images and obtains the corresponding GTiffs. The GTiff files are saved in the AppRoot directory. To change this option, provide AppRoot = <U+201C>full path<U+201D>. When untar = TRUE, the function decompresses the imagery. Image decompression duplicates the information due to the presence of both, compressed and decompressed images. Set raw.rm = TRUE to remove former ones.

Examples

Run this code
# NOT RUN {
# load a spatial polygon object of Navarre
data(ex.navarre)

src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)

# search and download the images from Landsat-8 between
# 2011 and 2013 in the region of Navarre
search.res <- ls8Search(startDate = as.Date("01-01-2018", "%d-%m-%Y"),
                        endDate = as.Date("20-01-2018", "%d-%m-%Y"),
                        extent = ex.navarre,
                        browseAvaliable = "Y",
                        AppRoot = src)

# download 1 image
lsDownSearch(searchres = search.res[1,], 
             username = "user", 
             password = "pass", 
             AppRoot = src,
             untar = TRUE)
# download 4 images
lsDownSearch(searchres = search.res[1:4,], 
             username = "user", 
             password = "pass",
             AppRoot = src, 
             untar = TRUE)
# download all the images
lsDownSearch(searchres = search.res, 
             username = "user", 
             password = "pass",
             AppRoot = src,
             untar = TRUE)

# search and download the images from Landsat-7 between
# 2011 and 2013 in the region of Navarre
src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)
search.res <- ls7Search(startDate = as.Date("01-01-2018", "%d-%m-%Y"),
                        endDate = as.Date("20-01-2018", "%d-%m-%Y"),
                        extent = ex.navarre,
                        browseAvaliable = "Y",
                        AppRoot = src)
# download 1 image
lsDownSearch(searchres = search.res[1,], 
             username = "user", 
             password = "pass", 
             untar = TRUE,
             AppRoot = src)
# download 4 images
lsDownSearch(searchres = search.res[1:4,], 
             username = "user", 
             password = "pass", 
             untar = TRUE, 
             AppRoot = src)
# download all the images
lsDownSearch(searchres = search.res, 
             username = "user", 
             password = "pass", 
             untar = TRUE, 
             AppRoot = src)

# removes the metadata to free memory space
lsRemoveMetadata()

# select Landsat-7 RGB bands
src.ls7 <- file.path(src,"Landsat7")
files <- list.files(src.ls7, 
                    pattern = "\\.TIF$", 
                    full.names = TRUE, 
                    recursive = TRUE)[c(6,5,4)]
files.stack <- stack(files)
qrange <- c(0.001, 0.999)
imagen <- varRGB(files.stack[[1]], 
                 files.stack[[2]],
                 files.stack[[3]],
                 qrange)
plotRGB(imagen)
# }

Run the code above in your browser using DataLab