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

View source: R/get_rgb.R

pa_get_rgbR Documentation

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",
  img.formats = c("jp2", "tif"),
  rgb.bands = c("B04", "B02", "B03"),
  fun = function(x) mean(x, na.rm = TRUE),
  verbose = TRUE
)

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.

img.formats

image formats to search for in the zipped file

rgb.bands

a vector containing the order of the RGB bands

fun

function to be applied to consolidate duplicated images

verbose

whether to display information on the progress of operations

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.

Value

an object of class rgb and stars

Author(s)

Caio dos Santos and Fernando Miguez

Examples


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)



pacu documentation built on June 8, 2025, 10:44 a.m.