# 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 images from Landsat-8 between
# 01-01-2018 and 20-01-2018 for the region of Navarre
lsDownSearch(satellite = "ls8",
username = "username",
password = "password",
startDate = as.Date("01-01-2018", "%d-%m-%Y"),
endDate = as.Date("20-01-2018", "%d-%m-%Y"),
pathrow = list(c(200, 31), c(200, 30)),
untar = TRUE,
AppRoot = wdir)
# define the path where the GTiff images are located
wdir.ls8 <- file.path(wdir,"Landsat8")
wdir.ls8.untar <- file.path(wdir.ls8,"untar")
# mosaic and crop the imagery
lsMosaic(src = wdir.ls8.untar,
AppRoot = wdir.ls8,
out.name = "Navarre",
extent = ex.navarre,
gutils = TRUE, # using gdalUtils
overwrite = TRUE) # overwrite
# generate the path where mosaicked images are located
wdir.ls8.navarre <- file.path(wdir.ls8, "Navarre")
# calculate the cloud mask from QC layer
lsCloudMask(src=wdir.ls8.navarre,
overwrite=TRUE)
# load the B1 layer and calculate the CLD layer
files.ls8.navarre.path <- list.files(wdir.ls8.navarre,
full.names = TRUE,
recursive = TRUE,
pattern = "\\.tif$")
tiles.ls8.cld <- files.ls8.navarre.path[grepl("CLD",files.ls8.navarre.path)]
tiles.ls8.b1 <- files.ls8.navarre.path[grepl("B1.tif",files.ls8.navarre.path)]
img.ls8.cld <- lapply(tiles.ls8.cld,raster)
img.ls8.b1 <- lapply(tiles.ls8.b1,raster)
# calculate cloud free b1 layers
img.ls8.b1.cloud.free <- img.ls8.b1[[1]] * img.ls8.cld[[1]]
spplot(img.ls8.b1.cloud.free)
# }
Run the code above in your browser using DataLab