def are_equal_color_table(color_table1: gdal.ColorTable, color_table2: gdal.ColorTable) -> bool: if color_table1.GetCount() != color_table2.GetCount(): return False for i in range(color_table1.GetCount()): color_entry1: gdal.ColorEntry = color_table1.GetColorEntry(i) color_entry2: gdal.ColorEntry = color_table2.GetColorEntry(i) if color_entry1 != color_entry2: return False return True
def write_color_table_to_file(color_table: gdal.ColorTable, color_filename: Optional[PathLikeOrStr]): if color_filename is None: color_filename = tempfile.mktemp(suffix='.txt') os.makedirs(os.path.dirname(color_filename), exist_ok=True) with open(color_filename, mode='w') as fp: for i in range(color_table.GetCount()): color_entry = color_table.GetColorEntry(i) color_entry = ' '.join(str(c) for c in color_entry) fp.write('{} {}\n'.format(i, color_entry)) return color_filename
def is_fixed_color_table(color_table: gdal.ColorTable, c=(0, 0, 0, 0)) -> bool: for i in range(color_table.GetCount()): color_entry: gdal.ColorEntry = color_table.GetColorEntry(i) if color_entry != c: return False return True