mosaic_crop: Crop a mosaic

View source: R/utils_mosaic.R

mosaic_cropR Documentation

Crop a mosaic

Description

Crop a SpatRaster object based on user-defined selection using an interactive map or plot.

Usage

mosaic_crop(
  mosaic,
  r = 3,
  g = 2,
  b = 1,
  re = 4,
  nir = 5,
  shapefile = NULL,
  show = c("rgb", "index"),
  index = "R",
  max_pixels = 5e+05,
  downsample = NULL,
  ...
)

Arguments

mosaic

A mosaic of class SpatRaster, generally imported with mosaic_input().

r, g, b, re, nir

The red, green, blue, red-edge, and near-infrared bands of the image, respectively. By default, the function assumes a BGR as input (b = 1, g = 2, r = 3). If a multispectral image is provided up to seven bands can be used to compute built-in indexes. There are no limitation of band numbers if the index is computed using the band name.

shapefile

An optional SpatVector, that can be created with shapefile_input().

show

The display option for the map view. Options are "rgb" for RGB view and "index" for index view.

index

The index to use for the index view. Defaults to "B".

max_pixels

Maximum number of pixels to render in the map or plot (default: 500000).

downsample

Downsampling factor to reduce the number of pixels (default: NULL). In this case, if the number of pixels in the image (width x height) is greater than max_pixels a downsampling factor will be automatically chosen so that the number of plotted pixels approximates the max_pixels.

...

Additional arguments passed to mosaic_view().

Details

This function uses the mosaic_view function to display an interactive map or plot of the mosaic raster, allowing users to draw a rectangle to select the cropping area. The selected area is then cropped from the input mosaic and returned as a new SpatRaster object. If shapefile is declared, the mosaic will be cropped to the extent of shapefile.

Value

A cropped version of mosaic based on the user-defined selection.

Examples

if(interactive()){
library(pliman)
# Load a raster showing the elevation of Luxembourg
mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))

# Generate an interactive map using 'mapview' (works only in an interactive section)
cropped <- mosaic_crop(mosaic)
mosaic_view(cropped)
}


TiagoOlivoto/pliman documentation built on Sept. 14, 2024, 2:24 a.m.