geotiff.js
geotiff.js copied to clipboard
how dow I read colur palette from a COG?
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.
Hello, you could try https://github.com/GeoTIFF/geotiff-palette and see if it helps in your use case?
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 :)
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.
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?
image.fileDirectory.ColorMap
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