4

My gdal fu is weak and I need help! ;)

I'm creating a mosaic in geotiff from hundreds of ecw. I created a list of all my rasters and used this command:

gdal_merge -o c:\temp\output_image.tif -q -v --optfile c:\temp\rasterlist.txt

It's working, but I'd like now to create one with only the red band. Is it possible to do it with gdal_merge?

Thanks!

4

The simplest way I can think of is to take the merged raster you have just made and save out the red band (perhaps using gdal_translate and the -b switch). Alternatively you could use QGIS' raster calculator to save only the red band as a new raster.

3

If you have the output_image.tif yet, you can follow the advice of @MappaGnosis, i.e.:

gdal_translate -b 1 output_image.tif output_red.tif

Alternatively, it's possible to extract the red band while building a VRT mosaic with gdalbuildvrt and then translate from VRT to GTIFF format:

gdalbuildvrt -input_file_list c:\temp\rasterlist.txt -b 1 output_red.vrt
gdal_translate output_red.vrt output_red.tif

The two main advantages are that it's required less space on disk (VRT are simply XML files) and the process is faster than creating the mosaic with all the bands.

2

It's highly inefficient to merge mosaic using gdal merge.

Instead, make a VRT (Virtual Dataset) and convert it to your favourite format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.