More colormap options!
See original GitHub issueWith #90 @DanSchoppe added a third colormap
to rio-tiler. While this is awesome, I think rio-tiler could do more for allowing user to define custom colormap.
colormap are used when translating a one band data array to the image format using the new array_to_image
(using GDAL using a simple translation:
https://github.com/cogeotiff/rio-tiler/blob/e512d8441e7ebb460d074a4a98a76051ad983b73/rio_tiler/utils.py#L386
So here ☝️ a rio_tiler.utils.array_to_image
compatible colormap object is usually an array of shape (256, 3)
c = get_colormap(format="gdal")
print(c.shape)
(256, 3)
print(c)
[
[255 255 255]
[250 250 250]
[246 246 246]
[242 242 242]
...
[255 1 191]
[255 1 207]
[255 1 223]
[255 1 239]
]
I first though we could have used a custom dict like
{
0: [255, 255, 255],
100: [255, 1, 191],
...
}
~to create a colormap fordiscrete
values, but dict are not hashable so the current code in rio_tiler.utils.array_to_image
won’t work.~
I do love the dict option for colormap (like Rasterio use https://github.com/mapbox/rasterio/blob/960a906dad2a4e426387ce048a52c6e90afdcd2b/docs/topics/color.rst#writing-colormaps) so I first check if we can maybe change the rio_tiler.utils.get_colormap
function to have to return a dictionary colormap (because it seems to be the default format for GDAL) and in the same time adapt the rio_tiler.utils.array_to_image
to work with dict.
In a second time we could add another utility function to create colormaps, it seems that matplotlib has some functionality but I’m not sure we should had more required module to rio-tiler.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (6 by maintainers)
FYI: in #92 I’ve updated
rio_tiler.utils.array_to_image
to allow discrete colormap passed as dictionaryNice thing about rio-tiler, is that it’s designed to be implementation agnostic to be used behind API or other functions (like rio-glui, remotepixel-tiler …). Passing a 3x256 array or dict via a POST message shouldn’t be a problem for you API. But I agree we need a tool which can create color map from a colormap definition (e.g. passing min/max color)
Well as mentioned earlier, rio-tiler is agnostic, user could totally add Matplotlib to its API and apply the colormap using something else that
rio-tiler.utils.array_to_image
function. Meaning: I think at one point I’d like to keep rio-tiler as simple as possible so we focus on tiling performances and not on third party implementation (e.g: serving images).