I have two small rasters. Same resolution, SRID, type, format. When I use gdal_merge, the console keeps running the command ad infinitum.

import time, os

ot = "UInt16"
of = "GTiff"
nodata = "255"
ps = "5 5"
output = r"D:\Tasks_D\merge_minpnt_bris_yate.tif"
input1 = r"D:\Tasks_D\Raster_dev\gdal_sql_minpnt_rec_bris_5m.tif"
input2 = r"D:\Tasks_D\Raster_dev\gdal_sql_minpnt_rec_yate_5m.tif"

merge = fr'gdal_merge.py -n {nodata} -a_nodata {nodata} -ot {ot} -o "{output}" -of {of} -ps {ps} "{input1}" "{input2}"'

Here is what my console looks like after I run, note that I have to kill the script otherwise it keeps repeating the console command until I get memory issues and even Blue Screen of Death (BSOD):


Same issue occurs even if I go the gdal_buildvt route. Either way, I've tried to let this run and nothing happens, just repeating code. This should only take a second or two. I've tried to run this on two other tifs, sometime overlapping tifs, sometimes ones adjacent to each other. No luck. Any ideas on what's happening?

FYI I have a powerful PC with 64GB RAM.

  • I guess that you have introduced a loop. Perhaps GDAL autotests give some help with doing it right github.com/OSGeo/gdal/blob/master/autotest/pyscripts/… – user30184 Jan 31 at 18:53
  • How could my script cause a loop? It’s a simple merge two files together... – Theo F Jan 31 at 23:29
  • 1
    I don't know what's happening. But I think that this question/answer will help you: calling gdal_merge into python script. – Gabriel De Luca Feb 1 at 4:50
  • 1
    Compare what happens if you run gdal_merge without your own code python gdal_merge.py -o test.tif test1.tif test2.tif. – user30184 Feb 1 at 20:20
  • 1
    I believe that your problem is that gdal_merge is itself a python script and you must call it right from python. Have a look at solution that @GabrielDeLuca pointed. I also believe that this question does not have a GIS component and belongs rather to stackoverflow. – user30184 Feb 3 at 10:14

Your Answer

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

Browse other questions tagged or ask your own question.