Learn R Programming

RGISTools (version 0.9.7)

senMosaic: Mosaic a set of Sentinel-2 images

Description

senMosaic merges the Sentinel-2 imagery that covers a region of interest on the same dates.

Usage

senMosaic(src, AppRoot, extent = NULL, out.name = "outfile",
  verbose = FALSE, gutils = FALSE, overwrite = FALSE, ...)

Arguments

src

the path of the folder with the Sentinel images in GTiff format.

AppRoot

the directory to save the mosaicked images.

extent

an extent, Raster*, or Spatial* object representing the region of interest.

out.name

the name of the folder that stores the outputs. By default, <U+201C>outfile<U+201D> is assigned.

verbose

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

gutils

logical argument. If TRUE, the function uses `GDAL' utilities for mosaicking.

overwrite

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

...

arguments for nested functions:

  • pathrow a list of vectors with the path and row numbers of the tiles concerning the region of interest.

  • bFilter a vector with the bands to be mosaicked. If not supplied, all bands are mosaicked.

  • dayFilter a vector with the capturing dates being considered for mosaicking. If not supplied, all dates are mosaicked.

Details

The function mosaics the imagery in the src folder. The folder can hold GTiff images from several tiles, dates and bands. When only a subset of bands or dates has to be mosaicked, the band names or dates should be provided through the argument bFilter or dayFilter. Band names are defined by the letter <U+201C>b<U+201D> and the two-digit band number (e.g., <U+2018>b01<U+2019>). The dates must be provided as a Date class object. Once mosaicked, the images can be cropped to fit the extent (optional). The extent can be defined in any coordinate reference system, since senMosaic automatically reproject the extent to match the projection of the image. The outputs will be placed in the AppRoot directory, under the folder named as out.name. If no name is provided, the folder is named <U+201C>outfile<U+201D>. To use gutils = TRUE, a proper installation of `GDAL' is required. This method is faster than the native `R' functions.

Examples

Run this code
# NOT RUN {
# load a spatial polygon object of Navarre
data(ex.navarre)
# main output directory
src <- paste0(tempdir(),"/Path_for_downloading_folder")
print(src)
# download Sentinel-2 images
senDownload(startDate = as.Date("2018210", "%Y%j"),
            endDate = as.Date("2018218", "%Y%j"),
            platform = "Sentinel-2",
            extent = ex.navarre,
            product = "S2MSI1C",
            pathrow = c("R094"),
            username = "username",
            password = "password",
            AppRoot = src)
# folder with the unzipped images
src.sen <- file.path(src, "Sentinel-2")
src.unzip <- file.path(src.sen, "unzip")
# mosaic the Sentinel-2 images
senMosaic(src.unzip,
          AppRoot = src.sen,
          gutils = TRUE,
          out.name = "Navarre")

# load and plot a Sentinel-2 image
files <- list.files(src.sen, pattern = "\\.tif$", full.names = TRUE ,recursive = TRUE)
# print Sentinel-2 bands
getRGISToolsOpt("SEN2BANDS")
file.rgb <- stack(files[grepl("TCI",files)][1])
plotRGB(file.rgb)
# }

Run the code above in your browser using DataLab