Geoscience Reference
In-Depth Information
To initialize a multi-band image you can list the values for each input band in
double quotes. The list must have the dimension of the input image. Alternatively,
you can duplicate the same input image on the command line. This is illustrated for
a three band output image, where the input image has only one band. The first two
bands are set to 0 and the third band is set to 255. Notice that if the -separate
option is not set, the output image will only have a single band, initialized to 0. With
the option -createonly , the output raster dataset is createdwith the pre-initialized
values, but no input image data is copied into it.
gdal_merge.py -separate -init "0 0 255" -createonly -o
output.tif input.tif input.tif input.tif
The list of input images can also be read from an option file by specifying the
general option --optfile . In the next sequence of commands, we first create a
text file containing the list of all GeoTIFF files in the current directory. We then use
this list as an argument to --optfile . The following snippet will create a mosaic
from the forest map scenes shown in Fig. 7.2 (see also Sect. 7.1). Pixels with value 0
are ignored by using the option -n 0 .
ls *.tif
3128535974-AB.tif
3146933672-CA.tif
3147135008-AA.tif
3200037126-CB.tif
3214834843-DC.tif
3216236173-BA.tif
3282836015-BB.tif
ls *.tif > list.txt
gdal_merge.py -pct -n 0 -init 0 -a_nodata 0 -o fmap_mosaic.tif
--optfile list.txt
The same result can be obtained with the equivalent command:
gdal_merge.py -pct -o fmap_mosaic.tif -n 0 -init 0 -a_nodata 0
*.tif
Invoking the script with many input files might fail due to memory allocation
problems, as gdal_merge.py reads all input files into memory. If you run the
script with the option -n to ignore no-data values, it creates multiple copies in
memory, making things even worse. For large images, it is therefore better to use
other tools such as gdalwarp or pkcomposite (see Sect. 12.2 ) .
 
 
Search WWH ::




Custom Search