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

Description Usage Arguments Details Value Examples

View source: R/lsDownload.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
lsDownload(
  searchres,
  username = NULL,
  password = NULL,
  AppRoot,
  lvl = 1,
  product = c("sr", "source_metadata"),
  verbose = FALSE,
  raw.rm = FALSE,
  untar = FALSE,
  overwrite = FALSE,
  nattempts = 5,
  l2rqname,
  ...
)

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.

l2rqname

character argument defining the name of the order for level 2 products.

...

arguments for nested functions.

  • dates a vector with the capturing dates being considered for downloading.

  • bFilter a vector with the bands to be extracted when untar=TRUE. If not supplied, all bands are extracted.

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 ‘tar.gz’. lsDownload decompresses the images and obtains the corresponding GTiffs. The GTiff files are saved in the AppRoot directory. To change this option, provide AppRoot = “full path”. When untar = TRUE, the function decompresses the imagery. When only a subset of bands is required, band names can be provided through the bFilter argument. The band names are specified by string “band” and the band number (e.g., “band1”). Image decompression duplicates the information due to the presence of both, compressed and decompressed images. Set raw.rm = TRUE to remove former ones.

Value

this function does not return anything. It saves the imagery as 'tar.gz’ (and GTiff files) in a folder called 'raw’ ('untar’) in the AppRoot directory.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
## Not run: 
# load a spatial polygon object of Navarre
data(ex.navarre)

wdir <- file.path(tempdir(),"Path_for_downloading_folder")
print(wdir)

# search and download the images from Landsat-8 between
# 2011 and 2013 in the region of Navarre
sres <- 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 = wdir)

# download 1 image
lsDownload(searchres = sres[1,], 
           username = "username", 
           password = "password", 
           AppRoot = wdir,
           untar = TRUE)
# download 4 images
lsDownload(searchres = sres[1:4,], 
           username = "username", 
           password = "password",
           AppRoot = wdir, 
           untar = TRUE)
# download all the images
lsDownload(searchres = sres, 
           username = "username", 
           password = "password",
           AppRoot = wdir,
           untar = TRUE)

# search and download the images from Landsat-7 between
# 2011 and 2013 in the region of Navarre
wdir <- file.path(tempdir(),"Path_for_downloading_folder")
print(wdir)
sres <- 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 = wdir)
# download 1 image
lsDownload(searchres = sres[1,], 
           username = "username", 
           password = "password", 
           untar = TRUE,
           AppRoot = wdir)
# download 4 images
lsDownload(searchres = sres[1:4,], 
           username = "username", 
           password = "password", 
           untar = TRUE, 
           AppRoot = wdir)
# download all the images
lsDownload(searchres = sres, 
           username = "username", 
           password = "password", 
           untar = TRUE, 
           AppRoot = wdir)

# removes the metadata to free memory space
lsRemoveMetadata()

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

## End(Not run)

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