Add stars layer to a leaflet map
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),
...
)
a mapview or leaflet object.
a stars layer.
the band number to be plotted.
the color palette (see colorNumeric
) or function
to use to color the raster values (hint: if providing a function, set
na.color
to "#00000000"
to make NA
areas transparent).
The palette is ignored if x
is a SpatRaster with a color table or if
it has RGB channels.
the base opacity of the raster, expressed from 0 to 1
the HTML string to show as the attribution for this layer
the layer id
the name of the group this raster image should belong to (see
the same parameter under addTiles
)
if TRUE
, automatically project x
to the map
projection expected by Leaflet (EPSG:3857
); if FALSE
, it's
the caller's responsibility to ensure that x
is already projected,
and that extent(x)
is expressed in WGS84 latitude/longitude
coordinates
character. Method used for estimating the new cell values of a SpatRaster. One of:
near
: nearest neighbor. This method is fast, and it can be the preferred method if the cell values represent classes. It is not a good choice for continuous values. This is used by default if the first layer of x
is categorical.
bilinear
: bilinear interpolation. This is the default if the first layer of x
is numeric (not categorical).
cubic
: cubic interpolation.
cubicspline
: cubic spline interpolation.
lanczos
: Lanczos windowed sinc resampling.
sum
: the weighted sum of all non-NA contributing grid cells.
min, q1, med, q3, max, average, mode, rms
: the minimum, first quartile, median, third quartile, maximum, mean, mode, or root-mean-square value of all non-NA contributing grid cells.
the maximum number of bytes to allow for the projected image (before base64 encoding); defaults to 4MB.
a list of additional options, intended to be provided by
a call to gridOptions
the data object from which the argument values are derived; by
default, it is the data
object provided to leaflet()
initially, but can be overridden.
currently not used.
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.
# \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)
# }
Run the code above in your browser using DataLab