I have a raster that represents a classification, this means each pixel can contain a value in a small set (for instance [0,1,2,3,4,5,6,7,8,9,10]). My file is around 2.4 MB which is pretty small considering that it is 5000x5000 pixels. When I create a naive copy using python gdal bindings the output file is 100 MB, around 40 times bigger! (by naive, I mean, I open the raster, extract the data array and write it to a new raster, using gdal_translate yields same result). Looking closely to both files using gdalinfo I see something interesting, in the original file:
Band 1 Block=256x256 Type=Byte, ColorInterp=Gray
in the new file:
Band 1 Block=5000x1 Type=Byte, ColorInterp=Gray
I guess that somehow the tif format can optimise the size when it finds redundant information, for example 256x256 pixel blocks with the same value. The question is, how can I write in 256x256 blocks instead of 5000x1 blocks?