Create a Red-Green-Blue image overlay from a RasterStack
/
RasterBrick
or stars
object based on three layers.
Three layers (sometimes referred to as "bands" because they may represent
different bandwidths in the electromagnetic spectrum) are combined such
that they represent the red, green and blue channel. This function can
be used to make 'true (or false) color images' from Landsat and other
multi-band satellite images. Note, this text is plagiarized, i.e. copied
from plotRGB
.
addRasterRGB
and addStarsRGB
are aliases.
Usage
addRasterRGB(
map,
x,
r = 3,
g = 2,
b = 1,
quantiles = c(0, 1),
domain = NULL,
na.color = "#BEBEBE80",
method = c("auto", "bilinear", "near", "average", "mode", "cubic", "cubicspline",
"lanczos", "sum", "min", "q1", "median", "q3", "max", "rms"),
...
)
addStarsRGB(
map,
x,
r = 3,
g = 2,
b = 1,
quantiles = c(0, 1),
domain = NULL,
na.color = "#BEBEBE80",
method = c("auto", "bilinear", "near", "average", "mode", "cubic", "cubicspline",
"lanczos", "sum", "min", "q1", "median", "q3", "max", "rms"),
...
)
Arguments
- map
a map widget object created from `leaflet()“
- x
a
RasterBrick
,RasterStack
or `stars“ raster object- r
integer. Index of the Red channel/band, between 1 and nlayers(x)
- g
integer. Index of the Green channel/band, between 1 and nlayers(x)
- b
integer. Index of the Blue channel/band, between 1 and nlayers(x)
- quantiles
the upper and lower quantiles used for color stretching. If set to NULL, stretching is performed basing on
domain
argument.- domain
the upper and lower values used for color stretching. This is used only if
quantiles
is NULL. If bothdomain
andquantiles
are set to NULL, stretching is applied based on min-max values.- na.color
the color to be used for NA pixels
- method
character. Method used for estimating the new cell values of a SpatRaster. One of:
bilinear
: bilinear interpolation (3x3 cell window). This is used by default if the first layer ofx
is not categoricalaverage
: This can be a good choice with continuous variables if the output cells overlap with multiple input cells.near
: nearest neighbor. This is used by default if the first layer ofx
is categorical. This method is not a good choice for continuous values.mode
: The modal value. This can be a good choice for categrical rasters, if the output cells overlap with multiple input cells.cubic
: cubic interpolation (5x5 cell window).cubicspline
: cubic B-spline interpolation. (5x5 cell window).lanczos
: Lanczos windowed sinc resampling. (7x7 cell window).sum
: the weighted sum of all non-NA contributing grid cells.min, q1, median, q3, max
: the minimum, first quartile, median, third quartile, or maximum value.rms
: the root-mean-square value of all non-NA contributing grid cells.- ...
additional arguments passed on to
addRasterImage
Details
Note, method auto
, the default, will choose between near
for factorial and
bilinear
for numeric data. All other methods need to be set manually.
Examples
# \donttest{
require(raster)
require(stars)
#> Loading required package: stars
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE
require(plainview)
#> Loading required package: plainview
require(leaflet)
leaflet() %>%
addTiles(group = "OpenStreetMap") %>%
addRasterRGB(plainview::poppendorf, 4,3,2, group = "True colours") %>%
addStarsRGB(st_as_stars(plainview::poppendorf), 5,4,3, group = "False colours") %>%
addLayersControl(
baseGroups = c("Satellite"),
overlayGroups = c("True colours", "False colours"),
)
# }