Add stars layer to a leaflet map
Usage
addStarsImage(
map,
x,
band = 1,
colors = "Spectral",
opacity = 1,
attribution = NULL,
layerId = NULL,
group = NULL,
project = FALSE,
method = c("auto", "bilinear", "near", "average", "mode", "cubic", "cubicspline",
"lanczos", "sum", "min", "q1", "median", "q3", "max", "rms"),
maxBytes = 4 * 1024 * 1024,
options = gridOptions(),
data = getMapData(map),
...
)Arguments
- map
a mapview or leaflet object.
- x
a stars layer.
- band
the band number to be plotted.
- colors
the color palette (see
colorNumeric) or function to use to color the raster values (hint: if providing a function, setna.colorto"#00000000"to makeNAareas transparent). The palette is ignored ifxis a SpatRaster with a color table or if it has RGB channels.- opacity
the base opacity of the raster, expressed from 0 to 1
- attribution
the HTML string to show as the attribution for this layer
- layerId
the layer id
- group
the name of the group this raster image should belong to (see the same parameter under
addTiles)- project
if
TRUE, automatically projectxto the map projection expected by Leaflet (EPSG:3857); ifFALSE, it's the caller's responsibility to ensure thatxis already projected, and thatextent(x)is expressed in WGS84 latitude/longitude coordinates- 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 ofxis 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 ofxis 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.- maxBytes
the maximum number of bytes to allow for the projected image (before base64 encoding); defaults to 4MB.
- options
a list of additional options, intended to be provided by a call to
gridOptions- data
the data object from which the argument values are derived; by default, it is the
dataobject provided toleaflet()initially, but can be overridden.- ...
currently not used.
Details
This is an adaption of addRasterImage. See that documentation
for 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{
library(stars)
library(leaflet)
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = read_stars(tif)
leaflet() %>%
addProviderTiles("OpenStreetMap") %>%
addStarsImage(x, project = TRUE)
#> Warning: no_data_value not set: missing values will appear as zero values
# }