Ticket #2950 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

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

Reported by: alobo Owned by: 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

Changed 4 years ago by alobo

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

Changed 4 years ago by rouault

  • owner changed from warmerdam to rouault

Changed 4 years ago by rouault

  • priority changed from high to normal
  • status changed from new to closed
  • resolution set to fixed
  • severity changed from blocker to normal
  • milestone set to 1.7.0

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

Changed 4 years ago by alobo

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.