Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#2950 closed defect (fixed)

gdal_merge.py error (Out of range band requested: 2)

Reported by: alobo Owned by: Even Rouault
Priority: normal Milestone: 1.7.0
Component: Utilities Version: unspecified
Severity: normal Keywords:
Cc:

Description

I run gdal_merge.py (from FWTools-2.0.6) and get:

$ /usr/local/FWTools-2.0.6/bin_safe/gdal_merge.py -v -o PICT0126radcorr.tif -separate PICT0126Nradcorr.tif PICT0126Rradcorr.tif PICT0126Gradcorr.tif

Filename: PICT0126Nradcorr.tif File Size: 2560x1920x1 Pixel Size: 1.000000 x 1.000000 UL:(0.000000,0.000000) LR:(2560.000000,1920.000000) Copy 0,0,2560,1920 to 0,0,2560,1920.

Filename: PICT0126Rradcorr.tif File Size: 2560x1920x1 Pixel Size: 1.000000 x 1.000000 UL:(0.000000,0.000000) LR:(2560.000000,1920.000000) Copy 0,0,2560,1920 to 0,0,2560,1920. Traceback (most recent call last):

File "/usr/local/FWTools-2.0.6/bin/gdal_merge.py", line 505, in ?

fi.copy_into( t_fh, 1, t_band, nodata )

File "/usr/local/FWTools-2.0.6/bin/gdal_merge.py", line 303, in copy_into

nodata_arg )

File "/usr/local/FWTools-2.0.6/bin/gdal_merge.py", line 133, in raster_copy

t_band = t_fh.GetRasterBand( t_band_n )

File "/usr/local/FWTools-2.0.6/pymod/gdal.py", line 648, in GetRasterBand

raise ValueError, 'Out of range band requested: %d' % i

ValueError: Out of range band requested: 2

Change History (4)

comment:1 by alobo, 15 years ago

Complementary info:

$ gdalinfo PICT0126Rradcorr.tif Driver: GTiff/GeoTIFF Files: PICT0126Rradcorr.tif Size is 2560, 1920 Coordinate System is `' Image Structure Metadata:

INTERLEAVE=BAND

Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 1920.0) Upper Right ( 2560.0, 0.0) Lower Right ( 2560.0, 1920.0) Center ( 1280.0, 960.0) Band 1 Block=2560x1 Type=Float32, ColorInterp=Gray

comment:2 by Even Rouault, 15 years ago

Owner: changed from warmerdam to Even Rouault

comment:3 by Even Rouault, 15 years ago

Milestone: 1.7.0
Priority: highnormal
Resolution: fixed
Severity: blockernormal
Status: newclosed

After a bit of code review and test, my guess is that your output file exists already, but with only 1 or 2 bands, and not the necessary 3 bands.

gdal_merge.py will create a file with the necessary number of files if it doesn't exist. Otherwise it will use it , and as new bandscannot be added after a file has been created, it will fail.

Explicit error message added in r16777

comment:4 by alobo, 15 years ago

True! I was surprised because the script was working with small subsets made with gdal_translate (which I was making to upload them). As soon as I deleted the partially made output file PICT0126radcorr.tif, the same command works. Don't know why PICT0126radcorr.tif existed, perhaps I made a first wrong run and then it was there to prevent the successful run of the right command.

Thanks!

Note: See TracTickets for help on using tickets.