I have 4 scenes of raster images that I need to merge. Average size of the scenes is only 60 MB, but the merged scene ended up at 6 GB in file size. Does anyone know why this happened?
If you have RGB Files you can use JPEG Compression + YCBCR. Add the following to your gdal_merge command:
-co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR
If you have RGBA files (RGB + alpha channel) leave out the PHOTOMETRIC part
if you don't have RGB images, you can use LZW Compression as suggested by dmci. ( + Use all CPUs for compression). Note: This has much worse performance than JPG Compression.
-co COMPRESS=LZW -co NUM_THREADS=ALL_CPUS
For better view performance, use inner tiling, for faster merging add some I/O Cache.
The command that I usually use is this one:
gdal_merge.py \ -of GTiff -ot Byte -o outfile.tif \ -co TILED=YES \ -co BLOCKXSIZE=512 \ -co BLOCKYSIZE=512 \ -co COMPRESS=JPEG \ -co PHOTOMETRIC=YCBCR \ --config GDAL_CACHEMAX 512 \ file1 file2 file3
At the End I use gdaladdo to add overviews for best performance!