addGeoRaster: Add stars/raster image to a leaflet map using optimised...

View source: R/addGeoRaster.R

addGeoRasterR Documentation

Add stars/raster image to a leaflet map using optimised rendering.

Description

Add stars/raster image to a leaflet map using optimised rendering.

Usage

addGeoRaster(
  map,
  x,
  group = NULL,
  layerId = NULL,
  resolution = 96,
  opacity = 0.8,
  options = leaflet::tileOptions(),
  colorOptions = NULL,
  project = TRUE,
  pixelValuesToColorFn = NULL,
  autozoom = TRUE,
  ...
)

Arguments

map

the map to add the raster data to.

x

the stars/raster object to be rendered.

group

the name of the group this raster image should belong to.

layerId

the layerId.

resolution

the target resolution for the simple nearest neighbor interpolation. Larger values will result in more detailed rendering, but may impact performance. Default is 96 (pixels).

opacity

opacity of the rendered layer.

options

options to be passed to the layer. See tileOptions for details.

colorOptions

list defining the palette, breaks and na.color to be used.

project

whether to project the RasterLayer to conform with leaflets expected crs. Defaults to TRUE and things are likely to go haywire if set to FALSE.

pixelValuesToColorFn

optional JS function to be passed to the browser. Can be used to fine tune and manipulate the color mapping. See https://github.com/r-spatial/leafem/issues/25 for some examples.

autozoom

whether to automatically zoom to the full extent of the layer. Default is TRUE

...

Further arguments passed to addGeotiff.

Details

This uses the leaflet plugin 'georaster-layer-for-leaflet' to render raster data. See https://github.com/GeoTIFF/georaster-layer-for-leaflet for details. The clue is that rendering uses simple nearest neighbor interpolation on-the-fly to ensure smooth rendering. This enables handling of larger rasters than with the standard addRasterImage.

Value

A leaflet map object.

Examples

if (interactive()) {
  library(leaflet)
  library(leafem)
  library(stars)

  tif = system.file("tif/L7_ETMs.tif", package = "stars")
  x1 = read_stars(tif)
  x1 = x1[, , , 3] # band 3

  leaflet() %>%
    addTiles() %>%
    leafem:::addGeoRaster(
      x1
      , opacity = 1
      , colorOptions = colorOptions(
        palette = grey.colors(256)
      )
    )
}


r-spatial/leafem documentation built on Nov. 1, 2024, 2:48 p.m.