Drawing Lines or Polygons with Raster Information
Usage
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)
)
Arguments
- mosaic
A mosaic of class
SpatRaster
, generally imported withmosaic_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.
- index
The index to use for the index view. Defaults to "B".
- show
The display option for the map view. Options are "rgb" for RGB view and "index" for index view.
- segment
Should the raster object be segmented? If set to
TRUE
, pixels within each polygon/rectangle will be segmented based on thethreshold
argument.- viewer
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 theset_pliman_viewer()
function. For example, you can runset_pliman_viewer("mapview")
to set the viewer option to "mapview" for all functions.- threshold
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.
- invert
Inverts the mask if desired. Defaults to
FALSE
.- summarize_fun
An optional function or character vector. When
summarize_fun = "mean"
, the mean values ofindex
are calculated within each object. For more details on available functions, refer toexactextractr::exact_extract()
.- buffer
Adds a buffer around the geometries of the SpatVector created. Note that the distance unit of
buffer
will vary according to the CRS ofmosaic
.- color_regions
The color palette for displaying index values. Defaults to
rev(grDevices::terrain.colors(50))
.- alpha
opacity of the fill color of the raster layer(s).
- 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 themax_pixels
.- quantiles
the upper and lower quantiles used for color stretching.
- plot
Plots the draw line/rectangle? Defaults to
TRUE
.- plot_layout
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.
Value
An invisible list containing the mosaic, draw_data, distance, distance_profile, geometry, and map.
Details
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) ofmosaic
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 thesummarize_fun
to compute a summary statistic for each object.
Examples
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)
}
#> Warning: The current raster is in the lat/lon coordinate system, which may result in processing errors when trying to segment individuals in the `mosaic_analyze()` function. It is highly suggested to reproject the raster using mosaic_project() with EPSG:32632
#> class : SpatRaster
#> dimensions : 90, 95, 1 (nrow, ncol, nlyr)
#> resolution : 0.008333333, 0.008333333 (x, y)
#> extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source : elev.tif
#> name : elevation
#> min value : 141
#> max value : 547
#>
#> Listening on http://127.0.0.1:6534
#> Error in UseMethod("st_transform"): no applicable method for 'st_transform' applied to an object of class "NULL"