Skip to content

RasterLayer

lonboard.RasterLayer

Bases: BaseLayer, Generic[T]

The RasterLayer renders raster imagery.

This layer expects input such as Cloud-Optimized GeoTIFFs (COGs) that can be efficiently accessed by internal tiles.

auto_highlight

auto_highlight = Bool(default_value=False)

When true, the current object pointed to by the mouse pointer (when hovered over) is highlighted with highlightColor.

Requires pickable to be True.

  • Type: bool
  • Default: False

before_id

before_id = Unicode(None, allow_none=True)

The identifier of a layer in the Maplibre basemap layer stack.

This deck.gl layer will be rendered just before the layer with the given identifier. You can find such an identifier by inspecting the basemap style JSON.

For example, in the Carto Positron style, if you look at the raw JSON data, each layer has an "id" property. The first layer in the basemap stack has "id": "background". So if you pass before_id="background", you won't see your deck.gl layer because it will be rendered below all layers in the Maplibre basemap.

A common choice for Carto-based styles is to use before_id="watername_ocean" so that your deck.gl layer is rendered above the core basemap elements but below all text labels.

Info

This only has an effect when the map's basemap is a MaplibreBasemap, and the map is rendering in "interleaved" mode.

debounce_time

debounce_time = Int(0)

Queue tile requests until no new tiles have been added for at least debounceTime milliseconds.

If debounceTime == 0, tile requests are issued as quickly as the maxRequests concurrent request limit allows.

If debounceTime > 0, tile requests are queued until a period of at least debounceTime milliseconds has passed without any new tiles being added to the queue. May reduce bandwidth usage and total loading time during interactive view transitions.

  • Default: 0

extensions

extensions = tag(sync=True, **(widget_serialization))

A list of layer extension objects to add additional features to a layer.

extent

extent = List(Float(), allow_none=True, default_value=None, minlen=4, maxlen=4)

The bounding box of the layer's data, in the form of [minX, minY, maxX, maxY].

If provided, the layer will only load and render the tiles that are needed to fill this box.

  • Default: null

highlight_color

highlight_color = VariableLengthTuple(
    Int(), default_value=(0, 0, 128, 128), minlen=3, maxlen=4
)

RGBA color to blend with the highlighted object (the hovered over object if auto_highlight=true). When the value is a 3 component (RGB) array, a default alpha of 255 is applied.

  • Type: List or Tuple of integers
  • Default: [0, 0, 128, 128]

max_cache_size

max_cache_size = Int(allow_none=True, default_value=None)

The maximum number of tiles that can be cached.

The tile cache keeps loaded tiles in memory even if they are no longer visible. It reduces the need to re-download the same data over and over again when the user pan/zooms around the map, providing a smoother experience.

If not supplied, the max_cache_size is calculated as 5 times the number of tiles in the current viewport.

  • Default: null

max_zoom

max_zoom = Int(allow_none=True, default_value=None)

The max zoom level of the layer's data.

When overzoomed (i.e. zoom > maxZoom), tiles from this level will be displayed.

  • Default: null

min_zoom

min_zoom = Int(0)

The min zoom level of the layer's data.

When underzoomed (i.e. zoom < minZoom), the layer will not display any tiles unless extent is defined, to avoid issuing too many tile requests.

  • Default: 0

opacity

opacity = Float(1, min=0, max=1)

The opacity of the layer.

  • Type: float. Must range between 0 and 1.
  • Default: 1

pickable

pickable = Bool(default_value=True)

Whether the layer responds to mouse pointer picking events.

This must be set to True for tooltips and other interactive elements to be available. This can also be used to only allow picking on specific layers within a map instance.

Note that picking has some performance overhead in rendering. To get the absolute best rendering performance with large data (at the cost of removing interactivity), set this to False.

  • Type: bool
  • Default: True

selected_index

selected_index = Int(None, allow_none=True)

The positional index of the most-recently clicked on row of data.

You can use this to access the full row of data from a GeoDataFrame

gdf.iloc[layer.selected_index]

Setting a value here from Python will do nothing. This attribute only exists to be updated from JavaScript on a map click. Note that pickable must be True (the default) on this layer for the JavaScript onClick handler to work; if pickable is set to False, selected_index will never update.

Note that you can use observe to call a function whenever a new value is received from JavaScript. Refer here for an example.

visible

visible = Bool(default_value=True)

Whether the layer is visible.

Under most circumstances, using the visible attribute to control the visibility of layers is recommended over removing/adding the layer from the Map.layers list.

In particular, toggling the visible attribute will persist the layer on the JavaScript side, while removing/adding the layer from the Map.layers list will re-download and re-render from scratch.

  • Type: bool
  • Default: True

zoom_offset

zoom_offset = Int(0)

This offset changes the zoom level at which the tiles are fetched. Needs to be an integer.

  • Default: 0

__init__

__init__(
    *,
    _tile_matrix_set: TileMatrixSet | None,
    _crs: CRS,
    _fetch_tile: FetchTile[T],
    _render_tile: RenderTile[T],
    _bounds: Bbox | None = None,
    _center: tuple[float, float] | None = None,
    **kwargs: Unpack[RasterLayerKwargs]
) -> None

from_geotiff

from_geotiff(
    geotiff: GeoTIFF,
    /,
    *,
    render_tile: RenderTile[Tile],
    **kwargs: Unpack[RasterLayerKwargs],
) -> RasterLayer[Tile]

Create a RasterLayer from a GeoTIFF instance from Async-GeoTIFF.

This supports visualizing virtually any GeoTIFF instance, no matter whether it's a local file or stored on a remote store like S3.

This works best with Cloud-Optimized GeoTIFFs (COGs) since they are designed for efficient access by internal tiles. But it will work with any tiled GeoTIFF.

Parameters:

  • geotiff (GeoTIFF) –

    A GeoTIFF instance from [Async-GeoTIFF]. Refer to the [Async-GeoTIFF] documentation for how to create a GeoTIFF from various input sources.

Other Parameters:

  • render_tile (RenderTile[Tile]) –

    A callback to transform a Tile into a PNG-formatted image. The callback must return an EncodedImage instance.

    Keep in mind that an async_geotiff.RasterArray stores pixel data in "band-major" order, meaning that the shape is (bands, height, width). You'll usually need to transpose the array to (height, width, bands) before converting to PNG. You can use the async_geotiff.utils.reshape_as_image utility function to do this.

    Also keep in mind that the tile data is not necessarily in visual RGBA format, so you may need to do some processing in render_tile to convert it to RGBA. For example, you might need to apply a color map to a single-band raster, or handle alpha compositing if the GeoTIFF has an alpha channel.

  • kwargs (Unpack[RasterLayerKwargs]) –

    parameters passed on to __init__

Returns:

from_pmtiles

from_pmtiles(
    reader: PMTilesReader, **kwargs: Unpack[RasterLayerKwargs]
) -> RasterLayer[Buffer | None]

Create a RasterLayer from a PMTiles archive.

Example:

Using obstore.store.HTTPStore to read a PMTiles file over HTTP:

from async_pmtiles import PMTilesReader
from lonboard import Map, RasterLayer
from obstore.store import HTTPStore

store = HTTPStore("https://air.mtn.tw")
reader = await PMTilesReader.open("flowers.pmtiles", store=store)
layer = RasterLayer.from_pmtiles(reader)
m = Map(layer)

Parameters:

  • reader (PMTilesReader) –

    A PMTilesReader instance from async-pmtiles. Refer to the async-pmtiles documentation for how to create a PMTilesReader from various input sources.

Other Parameters:

  • kwargs (Unpack[RasterLayerKwargs]) –

    parameters passed on to __init__

Raises:

  • ValueError –

    if the PMTiles tile type is not a supported raster format (i.e. PNG, JPEG, WEBP, or AVIF).

Returns:

  • RasterLayer[Buffer | None] –

    A new RasterLayer instance.