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?

asked Dec 9, 2014 at 10:50
2
  • Is there a typo at 'gm workspace'? Why is it two words? Commented Dec 9, 2014 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. Commented Dec 9, 2014 at 18:19

1 Answer 1

3

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...]
answered Dec 9, 2014 at 19:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.