Drawing Lines or Polygons with Raster Information
mosaic_draw(
mosaic,
r = 3,
g = 2,
b = 1,
re = 4,
nir = 5,
index = "NGRDI",
show = "rgb",
segment = FALSE,
viewer = c("mapview", "base"),
threshold = "Otsu",
invert = FALSE,
summarize_fun = NULL,
buffer = 2,
color_regions = rev(grDevices::terrain.colors(50)),
alpha = 1,
max_pixels = 1e+06,
downsample = NULL,
quantiles = c(0, 1),
plot = TRUE,
plot_layout = c(1, 2, 3, 3)
)
An invisible list containing the mosaic, draw_data, distance, distance_profile, geometry, and map.
A mosaic of class SpatRaster
, generally imported with
mosaic_input()
.
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.
The index to use for the index view. Defaults to "B".
The display option for the map view. Options are "rgb" for RGB view and "index" for index view.
Should the raster object be segmented? If set to TRUE
,
pixels within each polygon/rectangle will be segmented based on the
threshold
argument.
The viewer option. If not provided, the value is retrieved
using get_pliman_viewer()
. This option controls the type of viewer to use
for interactive plotting. The available options are "base" and "mapview".
If set to "base", the base R graphics system is used for interactive
plotting. If set to "mapview", the mapview package is used. To set this
argument globally for all functions in the package, you can use the
set_pliman_viewer()
function. For example, you can run
set_pliman_viewer("mapview")
to set the viewer option to "mapview" for
all functions.
By default (threshold = "Otsu"), a threshold value based on Otsu's method is used to reduce the grayscale image to a binary image. If a numeric value is informed, this value will be used as a threshold.
Inverts the mask if desired. Defaults to FALSE
.
An optional function or character vector. When
summarize_fun = "mean"
, the mean values of index
are calculated within
each object. For more details on available functions, refer to
exactextractr::exact_extract()
.
Adds a buffer around the geometries of the SpatVector created.
Note that the distance unit of buffer
will vary according to the CRS of
mosaic
.
The color palette for displaying index values. Defaults
to rev(grDevices::terrain.colors(50))
.
opacity of the fill color of the raster layer(s).
Maximum number of pixels to render in the map or plot (default: 500000).
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
.
the upper and lower quantiles used for color stretching.
Plots the draw line/rectangle? Defaults to TRUE
.
The de plot layout. Defaults to plot_layout = c(1, 2, 3, 3)
. Ie., the first row has two plots, and the second row has one plot.
The mosaic_draw
function enables you to create mosaic drawings from
remote sensing data and compute vegetation indices.
If a line is drawn using the "Draw Polyline" tool, the profile of index
is
displayed on the y-axis along the line's distance, represented in meter
units. It is important to ensure that the Coordinate Reference System (CRS)
of mosaic
has latitude/longitude units for accurate distance
representation.
If a rectangle or polygon is drawn using the "Draw Rectangle" or "Draw Polygon"
tools, the index
values are calculated for each object. By default, the
raw data is returned. You can set the summarize_fun
to compute a summary
statistic for each object.
if (interactive() && requireNamespace("EBImage")) {
library(pliman)
# Load a raster showing the elevation of Luxembourg
mosaic <- mosaic_input(system.file("ex/elev.tif", package="terra"))
# draw a polyline to see the elevation profile along the line
mosaic_draw(mosaic, buffer = 1500)
}
Run the code above in your browser using DataLab