Learn R Programming

pacu (version 0.1.74)

pa_get_rgb: Retrieve an RGB image from a zipped Sentinel 2 file

Description

Retrieve an RGB image from a zipped Sentinel 2 file

Usage

pa_get_rgb(
  satellite.images,
  aoi = NULL,
  pixel.res = "10m",
  check.clouds = FALSE,
  buffer.clouds = 100,
  img.formats = c("jp2", "tif"),
  rgb.bands = NULL,
  fun = function(x) mean(x, na.rm = TRUE),
  verbose = TRUE
)

Value

an object of class rgb and stars

Arguments

satellite.images

list of file paths to the Sentinel 2 zip files

aoi

NULL or an sf object used to crop the RGB raster to an area of interest

pixel.res

pixel resolution used to retrieve the RGB image. Can be one of 10m, 20m, 30m.

check.clouds

whether to check for clouds over the area of interest. If clouds are found, the function will skip cloudy images.

buffer.clouds

distance in meters around the area of interest within a cloud would be considered to interfere with the index calculation. This is useful to eliminate the effect of cloud shading from the analysis.

img.formats

image formats to search for in the zipped file

rgb.bands

DEPRECATED - the function now uses directly the true color image from Copernicus

fun

function to be applied to consolidate duplicated images

verbose

whether to display information on the progress of operations

Author

Caio dos Santos and Fernando Miguez

Details

This is script that unzips the Sentinel 2 zipped file into a temporary folder, searches for the RGB, and constructs a multi-band raster containing the RGB bands. If no ‘aoi’ is provided, the script will construct the RGB image for the area covered by the image. An important detail of this function is that, if there are duplicated dates, the function will consolidate the data into a single raster layer. The default behavior is to average the layers that belong to the same date. This can be changed with the 'fun' argument.

Examples

Run this code
# \donttest{
extd.dir <- system.file("extdata", package = "pacu")
## List of zipped Sentinel files in a directory
s2a.files <- list.files(extd.dir, '\\.zip', full.names = TRUE)
area.of.interest <- sf::st_read(file.path(extd.dir, 'cobs_a_aoi.shp'))
rgb.rast <- pa_get_rgb(satellite.images = s2a.files,
                            aoi = area.of.interest)
pa_plot(rgb.rast)
# }

Run the code above in your browser using DataLab