2

I confused that how to call python gdal module in the path such as gdal_calc.py(C:\Program Files (x86)\GDAL\gdal_calc.py) a test code below,but it don't work.

import os
os.sys('python C:\Program Files (x86)\GDAL\gdal_calc.py -A D:\temp\m2000049.tif -B D:\temp\m2000057.tif --outfile=D:\temp\result.tif --calc=(A+B)')

refect the error:

os.sys('python C:\Program Files (x86)\GDAL\gdal_calc.py -A D:\temp\m2000049.tif -B D:\temp\m2000057.tif --outfile=D:\temp\result.tif --calc=(A+B)') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 os.sys('python C:\Program Files (x86)\GDAL\gdal_calc.py -A D:\temp\m2000049.tif -B D:\temp\m2000057.tif --outfile=D:\temp\result.tif --calc=(A+B)')

TypeError: 'module' object is not callable

closed as off-topic by PolyGeo Dec 16 '16 at 6:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Might not help but try replacing all backward slashes with a single forward slash. – Joseph Dec 15 '16 at 10:28
  • Try with subprocess.call like this subprocess.call('gdal_calc.py -A file1 -B file2 --outfile=output.tif --calc=(A+B)', shell=True). Add gdal_calc.py path to environment variable afterwards no need to give full path. – S. Thiyaku Dec 15 '16 at 12:14
  • the problem has been solved. after installed winpython environ, it also need to add python path to windows environmental path variable. ps:it looks like that tif path need double quotation mark. – chaobin zhang Dec 15 '16 at 15:00
2

Did you try below, I think because inputs not parsed correctly :

import os
os.sys('python "C:\Program Files (x86)\GDAL\gdal_calc.py" -A "D:\temp\m2000049.tif" -B "D:\temp\\m2000057.tif" --outfile="D:\temp\\result.tif" --calc="(A+B)" ')

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