Closed HamedAlemo closed 3 months ago
@HamedAlemo I'm pretty sure this is a BUG with the GDAL GDALCreateCopy
method. you might want to open an issue in the GDAL or rasterio repo
from rasterio.io import MemoryFile
from rasterio.shutil import copy
from affine import Affine
profile = {
"driver": "GTiff",
"count": 1,
"dtype": "uint8",
"height": 512,
"width": 512,
"crs": "epsg:4326",
"transform": Affine(0.703125, 0.0, -180.0, 0.0, -0.3515625, 90.0),
}
with MemoryFile() as memfile_int:
with memfile_int.open(**profile) as src:
src.write_colormap(1, {0: (255, 0, 0, 255), 1: (0, 0, 0, 0)})
print(min(src.colormap(1)), max(src.colormap(1)))
out_profile = profile
with MemoryFile() as memfile_out:
copy(src, memfile_out.name, **profile)
with memfile_out.open() as dst:
print(min(dst.colormap(1)), max(dst.colormap(1)))
0 1
0 255
Thanks @vincentsarago for looking into this. I'll submit an issue w rasterio.
Hi All, We are translating some GeoTIFF files to COG using
cog_translate
. We pass a colormap as following to the function, and the resulting file is validated as COG. But when we load it in QGIS the colormap is extended to 255 while there are no pixels with values greater than 6 in the file. Is there a way to avoid this?The palette in QGIS shows up as this: