Skip to content

Colormap

async_geotiff.colormap

High-level Colormap class for GeoTIFF colormaps.

Colormap dataclass

A representation of a GeoTIFF colormap.

GeoTIFF colormaps

as_array

as_array(*, dtype: type[uint8 | uint16] = uint8) -> NDArray

Return the colormap as a NumPy array with shape (N, 3) and dtype uint16.

Each row corresponds to a color entry in the colormap, with columns representing the Red, Green, and Blue components respectively.

This is the most efficient way to access and apply the colormap data.

geotiff = await GeoTIFF.open(...)
array = await geotiff.fetch_tile(0, 0)

colormap = geotiff.colormap
colormap_array = colormap.as_array()

rgb_data = colormap_array[array.data[0]]
# A 3D array with shape (height, width, 3)

Returns:

  • NDArray

    A NumPy array representation of the colormap.

as_dict

as_dict(
    *, dtype: type[uint8 | uint16] = uint8
) -> dict[int, tuple[int, int, int]]

Return the colormap as a dictionary mapping indices to RGB tuples.

Returns:

  • dict[int, tuple[int, int, int]]

    A dictionary where keys are indices and values are tuples of (Red, Green, Blue) components.

as_rasterio

as_rasterio() -> dict[int, tuple[int, int, int, int]]

Return the colormap as a mapping to 8-bit RGBA colors.

This returns a colormap in the same format as rasterio's DatasetReader.colormap method.

This is the same as Colormap.as_dict with:

  • dtype set to np.uint8
  • an added alpha channel set to 255, except for the nodata value, if defined, which has an alpha of 0.

Returns:

  • dict[int, tuple[int, int, int, int]]

    Mapping of color index value (starting at 0) to RGBA color as a 4-element tuple.