[gdal-dev] Calling gdal_merge from a Python script

Robin Wilson robin at rtwilson.com
Fri Aug 26 04:01:15 PDT 2016


Hi,

I've was very happy to see the RFC 59.1 code merged in GDAL 2.1, allowing the use of some of the GDAL command-line utilities from within Python without having to 'shell out' using something like the subprocess module.

I notice that gdal_merge isn't in the list of command-line utilities that have been wrapped to be accessed programmatically - and that, in fact, as far as I can see none of the Python-based command-line utilities have been wrapped.

Are there any plans to provide programmatic access to gdal_merge.py and the other Python-based utilities?

If not, what is the best suggested way to use this from a Python script? Using subprocess can be quite brittle (I've had lots of issues with paths etc, particularly on Windows machines - and being able to `import gdal` in Python is in no way related to being able to run gdal_merge.py from the shell), but the only other way seems to be to manipulate the path somehow to try and import gdal_merge.py, and then manipulate sys.argv to 'fake' the command-line arguments to gdal_merge.py - which also seems quite brittle.

Any thoughts?

Robin



More information about the gdal-dev mailing list