2

I want to mosaic 2 rasters "rasa" and "rasb" using gdal_merge.py . While running the code, it produces an error " No input files selected". Can somebody help me to find the error in the code?

    import subprocess
    filea = 'C:/Users/claudio/workspace/test/test1/rasa.tif'
    fileb = 'C:/Users/claudio/workspace/test/test1/rasb.tif'
    output = 'C:/Users/claudio/workspace/test/test1/output.tif'
    subprocess.call(['gdal_merge','-o',output,filea,fileb],shell=True)

when i run the above code, the output i am getting is: enter image description here

5
  • have you tried directly from the command line? Which OS are you using? Apr 5, 2016 at 9:14
  • I am trying it in eclipse pydev. OS: Windows 7, python v 3.4
    – Claudio
    Apr 5, 2016 at 9:24
  • so why don't you import gdal_merge instead of calling it from the command line? try to find a way to print or log the statement you are sending to the command line. I guess something is going wrong there. Maybe you can first try to switch subprocess to os.system(). and do it simple os.system('gdal_merge -o ' + output + ' ' + filea + ' ' + fileb). Maybe the spaces are missing in the subprocess command. Apr 5, 2016 at 10:07
  • Try just running it from the C:\Users\claudio\workspace\test\test1 directory, without the full paths.
    – BradHards
    Apr 5, 2016 at 10:53
  • You seem to have created two accounts which makes it hard for you to communicate with potential answerers. Please follow these instructions to merge your two accounts ASAP: gis.stackexchange.com/help/merging-accounts
    – PolyGeo
    Apr 5, 2016 at 11:04

2 Answers 2

1

The problem is you are passing a list to subprocess then specifying shell=True (which expects a string as input) so it is only taking the first item in the list, which is gdal_merge, and running this. Just running gdal_merge.py gives the same error.

The same code but without shell=True should work:

import subprocess
filea = 'C:/Users/claudio/workspace/test/test1/rasa.tif'
fileb = 'C:/Users/claudio/workspace/test/test1/rasb.tif'
output = 'C:/Users/claudio/workspace/test/test1/output.tif'
subprocess.call(['gdal_merge', '-o' , output, filea, fileb])
0

Do the files at the paths filea and fileb exist?

Try:

filea = r'C:/Users/claudio/workspace/test/test1/rasa.tif'
fileb = r'C:/Users/claudio/workspace/test/test1/rasb.tif'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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