rio-tiler icon indicating copy to clipboard operation
rio-tiler copied to clipboard

Add indexes option to img.render() ?

Open chrieke opened this issue 4 years ago • 1 comments

Using img.render() with an ImageData.data array with too many bands fails with CPLE_NotSupportedError: PNG driver doesn't support 5 bands. Must be 1 (grey), 2 (grey+alpha), 3 (rgb) or 4 (rgba) bands.

Example:

src_path = "https://naipblobs.blob.core.windows.net/naip/v002/al/2019/al_60cm_2019/30087/m_3008701_ne_16_060_20191115.tif"
with COGReader(src_path) as cog:
    img = cog.preview()    
    print(img.data.shape)  # >>> (4, 1024, 892)

img.render()

Reading all bands and later visualizing a band subset (without mutating the array) seems like a common usecase. Would propose to add an indexes parameter to .render(), so that specific bands can be selected for the vizualization.

Happy to make a PR, but wanted to check first if there is a better solution or this is not intended etc.

chrieke avatar Feb 05 '21 19:02 chrieke

@chrieke I think this is a nice feature.

The render function (https://github.com/cogeotiff/rio-tiler/blob/a97ece18173b54c6a8bfaa091a3f47111460a3c7/rio_tiler/utils.py#L277) is quite old and complexe, feel free to start a WIP pr and then we can jump on if you have question

vincentsarago avatar Feb 05 '21 19:02 vincentsarago