GDAL_MERGE(1) | GDAL | GDAL_MERGE(1) |
gdal_merge - Mosaics a set of images.
gdal_merge.py [--help] [--help-general] [-o <out_filename>] [-of <out_format>] [-co <NAME>=<VALUE>]... [-ps <pixelsize_x> <pixelsize_y>] [-tap] [-separate] [-q] [-v] [-pct] [-ul_lr <ulx> <uly> <lrx> <lry>] [-init "<value>[ <value>]..."] [-n <nodata_value>] [-a_nodata <output_nodata_value>] [-ot <datatype>] [-createonly] <intput_file> [<intput_file>]...
This utility will automatically mosaic a set of images. All the images must be in the same coordinate system and have a matching number of bands, but they may be overlapping, and at different resolutions. In areas of overlap, the last image will be copied over earlier ones. Nodata/transparency values are considered on a band by band level, i.e. a nodata/transparent pixel on one source band will not set a nodata/transparent value on all bands for the target pixel in the resulting raster nor will it overwrite a valid pixel value.
The creation options available vary by format driver, and some simple formats have no creation options at all. A list of options supported for a format can be listed with the --formats command line option but the documentation for the format is the definitive source of information on driver creation options. See Raster drivers format specific documentation for legal creation options for each format.
NOTE:
gdal_merge.py -init 255 -o out.tif in1.tif in2.tif
The first two bands will be initialized to 0 and the third band will be initialized to 255.
gdal_merge.py -init "0 0 255" -o out.tif in1.tif in2.tif
A large list of files can be passed to gdal_merge by listing them in a text file using:
ls -1 *.tif > tiff_list.txt
on Linux, or
dir /b /s *.tif > tiff_list.txt
on Windows. The text file can then be passed to gdal_merge using --optfile:
gdal_merge.py -o mosaic.tif --optfile tiff_list.txt
Conduct "merging by stacking" with the -separate flag. Given three greyscale files that cover the same area, you can run:
gdal_merge.py -separate 1.tif 2.tif 3.tif -o rgb.tif
This maps 1.tif to red, 2.tif to green and 3.tif to blue.
The last image in the input line comes out on top of the finished image stack. You might also need to use -n to note which value should not be copied into the destination image if it is not already defined as nodata.
gdal_merge.py -o merge.tif -n 0 image1.tif image2.tif image3.tif image4.tif
Frank Warmerdam <warmerdam@pobox.com>, Silke Reimer <silke@intevation.de>
1998-2024
February 8, 2024 |