5

I'm also having problems with running gdal_merge.py within another python script and I cannot run it. I already checked a similar problem here. My example is as follows:

First I set my workspace and locations:

sys.path.append('C:/Python27/ArcGIS10.2/Scripts/') 
import gdal_merge as gm workspace="D:/Satellitendaten/rapideye/img/testregion/cannyedge/out/"
os.chdir(workspace)

Then I run:

sys.argv = ['o', 'out.tif', 'allre1.tif', 'allre10.tif', 'allre11.tif', 'allre12.tif', 'allre13.tif', 'allre14.tif', 'allre15.tif', 'allre16.tif', 'allre17.tif', 'allre18.tif', 'allre2.tif', 'allre3.tif', 'allre4.tif', 'allre5.tif', 'allre6.tif', 'allre7.tif', 'allre8.tif', 'allre9.tif']

I get:

0...10...20...30...40...50...60...70...80...90...100 - done.

But also ERROR 4:

`out.tif' does not exist in the file system, and is not recognised as a supported dataset name.

So the output is not created. Maybe someone can help me out with the issue to merge different tif files to a single tif?

  • Is there a typo at 'gm workspace'? Why is it two words? – camdenl Dec 9 '14 at 15:06
  • Just a thought, setting sys.argv as you are may be causing a problem. sys.argv[0] is always the path of the current script running. Whenever I pass in args in this way I usually do sys.argv[1:] = [#your args here]. I should add that when I do that, it is when using ArcGIS/arcpy so it may not apply for gdal. – crmackey Dec 9 '14 at 18:19
2

As crmackey notes in his comment, the first element in sys.argv needs to be the current script. You also need to use '-o' instead of 'o' as your first argument for gdal_merge

Try:

sys.path.append('C:/Python27/ArcGIS10.2/Scripts/') 
import gdal_merge as gm 
workspace="D:/Satellitendaten/rapideye/img/testregion/cannyedge/out/"
os.chdir(workspace)

sys.argv[1:] = ['-o', 'out.tif', 'allre1.tif', etc...]

Your Answer

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

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