I have this simple code that batch sieves all the raster in a given directory. I found outthat the resulting output files (241MB )are pretty much larger than the input(~31MB). In ArcGIS, there is a way to enable compression like LZW, how to do it it QGIS python? Is there a way to insert it in this code?
from qgis.core import * #importing the QGIS processing core
import os, subprocess, glob
input = "/data/brent/GAUP/sen2agri_two_years/"
output_dir = "/data/brent/GAUP/sen2agri_two_years/sieved//"
os.chdir(input)
for fname in glob.glob("S2*.TIF"):
print fname
name= list(os.path.splitext(fname))
name[0] = name[0] + "_sieved"
newName = "".join(name)
print "processing " + newName
subprocess.call(["gdal_sieve.py", "-st", "20", "-4", fname, "-of", "GTiff", output_dir+newName])
-co COMPRESS=LZW
as documented in gdal.org/frmt_gtiff.html. Otherwise you can create a temporary output, perhaps info memory, and copy that into compressed tiff afterwards.