# NOT RUN {
# load a spatial polygon object of Navarre
data(ex.navarre)
src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)
# search and download images from Landsat-8 between
# 01-01-2018 and 20-01-2018 for the region of Navarre
lsDownload(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 = src)
# define the path where the GTiff images are located
src.ls8 <- file.path(src,"Landsat8")
src.untar <- file.path(src.ls8,"untar")
# calculate the cloud mask from QC layer
lsCloudMask(src=src.untar,
overwrite=TRUE,
AppRoot = src.ls8)
# mosaic and crop the imagery
lsMosaic(src = src.untar,
AppRoot = src.ls8,
out.name = "Navarre",
extent = ex.navarre,
bFilter = c("CLD"),
gutils = TRUE, # using gdalUtils
overwrite = TRUE) # overwrite
# generate the path where mosaicked images are located
src.navarre <- file.path(src,"Landsat8","Navarre")
# load the B1 layer and calculate the CLD layer
tiles.path <- list.files(src.navarre,
full.names = TRUE,
recursive = TRUE,
pattern = "\\.tif$")
cloud.tiles <- tiles.path[grepl("CLD",tiles.path)]
b1.tiles <- tiles.path[grepl("B1.tif",tiles.path)]
cloud.tiles.ras <- lapply(cloud.tiles,raster)
b1.tiles.ras <- lapply(b1.tiles,raster)
# calculate cloud free b1 layers
b1.cloud.free <- b1.tiles.ras[[1]] * cloud.tiles.ras[[1]]
spplot(b1.cloud.free)
# }
Run the code above in your browser using DataLab