2

Could someone navigate me for using/calling GDAL stand-alone programs from Python? I have GDAL 2.3.2 and Python 3.7. When I call gdal from python I can access to a limited number of functions including gdal.Warp() and gdal.Translate(). I can not however access 'gdal_edit' which I am currently interested to use. In the Git page of this function I did not find any information regarding access to this function either!

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Nov 18, 2019 at 15:01

1 Answer 1

6

gdal_edit is itself a python script - you should be able to find it located within your GDAL installation.

To access it from Python, you can use the subprocess library to call the script. e.g.

import subprocess as sp
#locate your gdal_edit script
gdaledit = r"C:\Program Files\GDAL\gdal_edit.py"
#input data 
srcdata = 'abc.tif'
cmd = [gdaledit, '-a_srs', 'EPSG:4326', '-tr', '150', srcdata]
sp.check_call(cmd, shell=True)

You use the shell=True argument so that Python can effectively run the script from the command line. Without it, you will get an error.

answered Nov 18, 2019 at 15:42
2
  • Yes, that's what i usually do, too. But as i read the question, i thought, that you also can try to Import those Scripts to get more control over the process. Commented Nov 19, 2019 at 7:28
  • Yes Andreas, after GDAL 2.0.0 you can directly call some functions (without the need of using subprocess) but not all of them (including gdal_edit, gdal_merge, etc.) Commented Nov 19, 2019 at 9:20

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.