Tuesday, 1 November 2016

gdal - Error 193 while running gdal_calc.py using subprocess.call in Python


The following code works when used with cmd prompt:


C:\gdal_calc.py -A C:\a.tif --outfile=C:\result.tif --calc="A+1"

When I want to run the same code with subprocess:


import subprocess


subprocess.call(['C:\\gdal_calc.py', '-A', 'C:\\a.tif', '--outfile=C:\\result.tif', '--calc="A+1"'])

The following error results:


[Error 193] %1 is not a valid Win32 application


Please help me. I am highly frustating with it. This problem is basically the syntax error when the parameters are fed up into subprocess.call method what I think.


Here is the reference: http://www.gdal.org/gdal_calc.html


gdal_calc.py file is here: http://svn.osgeo.org/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py



Answer



The gdal_calc.py script isn't an executable. Try calling python gdal_calc.py etc...


subprocess.call([sys.executable, 'C:\\gdal_calc.py', '-A', 'C:\\a.tif', '--outfile=C:\\result.tif', '--calc="A+1"'])

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...