# NOT RUN {
# load a spatial polygon object of Navarre
data(ex.navarre)
# Download S2MSI1C products sensed by Sentinel-2
# between the julian days 210 and 218, 2018
src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)
senDownload(startDate = as.Date("2018210", "%Y%j"),
endDate = as.Date("2018218", "%Y%j"),
platform = "Sentinel-2",
extent = ex.navarre,
product = "S2MSI2A",
pathrow = c("R094"),
username = "username",
password = "password",
AppRoot = src)
# define the paths to the Sentinle-2 images and the
# folder with the unzipped images
src.sen2 <- file.path(src, "Sentinel-2")
src.unzip <- file.path(src.sen2, "unzip")
# mosaic the Sentinel-2 images
senMosaic(src.unzip,
AppRoot = src.sen2,
gutils = TRUE,
out.name = "Navarre")
# calculate the cloud mask
src.navarre <- file.path(src.sen2, "Navarre")
senCloudMask(src = src.navarre,
img.res = "60m",
overwrite = TRUE,
sensitivity = 98,
AppRoot = src.sen2)
# define the path for the Sentinel-2 cloud mask
src.cloud <- file.path(src.sen2, "CloudMask")
# select B02 images of 60 meters
tiles.navarre <- list.files(src.navarre,
full.names = TRUE,
recursive = TRUE,
pattern = "\\.tif$")
b2.tiles <- tiles.navarre[grepl("B02",tiles.navarre)]
b2.tiles <- b2.tiles[grepl("60m",b2.tiles)]
# generate a 60-meter resolution cloud mask
cloud.tiles <- list.files(src.cloud,
full.names = TRUE,
pattern = "\\.tif$")
cloud.tiles <- cloud.tiles[grepl("60m",cloud.tiles)]
# remove the cloud mask from b02 tiles
b2.tiles.stack <- stack(b2.tiles)
cloud.tiles.stack <- stack(cloud.tiles)
b2.cloud.free <- b2.tiles.stack*cloud.tiles.stack
# plot b2 cloud free layers
spplot(b2.cloud.free)
# }
Run the code above in your browser using DataLab