[FWTools] gdal_merge with nodata value

Bryan Keith bryan at geomega.com
Thu Oct 26 15:40:36 EDT 2006


I'm running the gdal_merge python script from an FWTools1.0.7 
installation on a Windows2000 machine with Visual Studio installed.  My 
4 input tifs are 1 band 1 byte (0-255 grayscale) images.  I can merge 
them without specifying a nodata value, and the output is fine (except 
in nodata areas):

gdal_merge -o test.tif Portland.tif Linnton.tif Sauvie_Island.tif 
Vancouver.tif

When I specify nodata with the -n flag, then the script crashes and 
brings up Visual Studio debugging window:

gdal_merge -o test.tif -n 0 Portland.tif Linnton.tif Sauvie_Island.tif 
Vancouver.tif

The line that is failing in the Python script is
nodata_test = Numeric.equal(data_src,nodata)
in the raster_copy_with_nodata routine.

I tried changing the nodata value to an integer (essentially undoing a 
change that Frank made in Revision 1.24  2006/01/26 23:40:39  fwarmerdam):
elif arg == '-n':
   i = i + 1
   #nodata = float(argv[i])
   #bryan changed
   nodata = argv[i]

That caused the script to run for a very long time and return this error:
Traceback (most recent call last):
   File "C:\Programs\FWTOOL~1.7\bin\gdal_merge.py", line 514, in ?
     fi.copy_into( t_fh, band, band, nodata )
   File "C:\Programs\FWTOOL~1.7\bin\gdal_merge.py", line 312, in copy_into
     nodata_arg )
   File "C:\Programs\FWTOOL~1.7\bin\gdal_merge.py", line 127, in raster_copy
     nodata )
   File "C:\Programs\FWTOOL~1.7\bin\gdal_merge.py", line 168, in 
raster_copy_with_nodata
     nodata_test = Numeric.equal(data_src,nodata)
MemoryError: can't allocate memory for array

So I gave up on Windows and tried on linux with an old version of 
FWTools (1.0.0a7) and an old version of gdal_merge.py (Revision 1.21), 
and I got the same memory error that I ended up with on windows (albeit 
much more quickly).  Now I'm thinking that specifying the nodata flag 
does indeed use much more memory than without it and that I'll have to 
bump up available memory to get these files to process.

Any other ideas?

Bryan


More information about the FWTools mailing list