geotiff.js icon indicating copy to clipboard operation
geotiff.js copied to clipboard

how dow I read colur palette from a COG?

Open pitommasi opened this issue 1 year ago • 6 comments

I need to display some COG using OpenLayers. So far I managed to do so but I had to specify the palette separately. Since the COG I'm using have the colormap already embedded (https://rasterio.readthedocs.io/en/latest/topics/color.html#writing-colormaps), I've been wondering whether there was a way to extract it dynamically from the COG instead of hardcoding it in the JS code.

pitommasi avatar Jul 29 '23 13:07 pitommasi

Hello, you could try https://github.com/GeoTIFF/geotiff-palette and see if it helps in your use case?

DanielJDufour avatar Jul 29 '23 13:07 DanielJDufour

Hi, thanks, I'll give it a go... I asked the same question there but didn't get a reply, hence, I've asked here :)

pitommasi avatar Jul 29 '23 14:07 pitommasi

The palette is stored in a TIFF Tag ColorMap.

We expose RGB reading using palettes in the GeoTIFF Image class and pass it to the fromPalette function. There is currently no predefined function to do so, but everything is accesible, I believe.

constantinius avatar Jul 31 '23 12:07 constantinius

So I would I read the palette to pass it to a style? I mean, I know how to pass it to the style, eventually, but how do I retrieve it?

pitommasi avatar Jul 31 '23 13:07 pitommasi

image.fileDirectory.ColorMap

constantinius avatar Aug 02 '23 14:08 constantinius

If your goal is to color your COG then the library already includes the required functionality if you use the readRGB function: https://github.com/geotiffjs/geotiff.js/blob/4af107db0b0a8b46213d444de924575b5c9255da/src/geotiffimage.js#L646

Note that if you use this library behind OpenLayers you may run into this issue: https://github.com/openlayers/openlayers/issues/15894

SlowMo24 avatar Jun 05 '24 10:06 SlowMo24