I am in need of merging rasters within Python script or interpreter, not outside using a command line tool such as gdal_merge.py. Is there a simple way? Or is there a way of executing the command line tool from inside a python script?

  • I’m a bit confused, gdal_merge.py is within Python. Why will that not work for you?
    – Aaron
    Jul 4, 2018 at 3:51
  • Being it a file, can I call it from inside another .py file? If so, how? Jul 4, 2018 at 3:53
  • From what I have seen, gdal_merge.py is a command line tool, I dont know if I can execute that from inside another python script. Jul 4, 2018 at 3:59
  • Could you please edit your question with these pertinent details?
    – Aaron
    Jul 4, 2018 at 4:13

1 Answer 1


Yes, you can call the command line tool from the python script. The library that enables you to do this is subprocess. The beginning of the page also lists some older libraries.

Here is one short exmaple:

# Import module
import subprocess

# Formulate the command as string I used the gdal_translate here
cmd = 'gdal_translate -ot FLOAT32 -of AAIGrid ras1.tif ras2.asc'

# Call
subprocess.call(cmd, shell=True')

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.