1

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?

  • If you're not interested in using the correct datatype, then you really aren't interested in a solution. – Vince Aug 6 '16 at 0:28
  • @Vince I didn't write the code that generated the original raster, I know how to solve that problem. I wanted to focus on the problem I can't handle. I added the note to prevent obvious remarks. The question has been modified. – amaurs Aug 6 '16 at 1:21
  • Use the TILED=YES creation option, see gdal.org/frmt_gtiff.html – BradHards Aug 6 '16 at 1:32
  • @BradHards Is it possible to use that option with python? – amaurs Aug 6 '16 at 4:26
  • 2
    Tiled 256x256 blocks or striped 1x5000 organization makes only marginal difference. Your original image must be compressed while the new is not. Check with gdalinfo. – user30184 Aug 6 '16 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.