gdal_calc.py outputs huge files

Use the --co=creationoptions parameter to compress the output.

gdal_calc.py --co="COMPRESS=LZW" -A map.tif --outfile=deforestation_00-10.tif --NoDataValue=0 --calc="A >= 7"

For more compression options, see the GDAL GTiff format description.


Filesize question

If the result data is boolean True/False (or 1s and 0s), use --type=Byte with the creation option NBITS=1 to create a file with 1 bit per sample. This will pack the uncompressed data 8 times smaller. And then as @Luke has answered, specify a compression to use. There are a dozen different compression methods; another good one is COMPRESS=DEFLATE.

gdal_calc -A map.tif --outfile=out.tif --type=Byte --co="NBITS=1" --co="COMPRESS=DEFLATE" --calc="A >= 7"

With some example data that I have, I'm seeing a compression ratio of 0.15%. So I'd expect a result from a 1.37GB file to compress down to about 2MB.

Bonus question

According to the help for --calc:

calculation in gdalnumeric syntax using +-/* or any numpy array functions (i.e. logical_and())

The expression is processed by eval. So try this:

--calc="logical_or(logical_and(A >= 7, A <= 9), logical_and(A >= 10, A <= 12))"

I wasn't sure what the whole * 2 part of your original expression was, so it is left out.

Tags:

Gdal

Raster