I'm trying to run gdalwarp from within a python script

    start = "gdalwarp -overwrite -ts 22 20 -r average -srcnodata 99 "
    input_file = filename[12:]
    output_file = "temp1.tif"
    print start + input_file + ' ' +output_file
    subprocess.call([r'%s %s output.tif' % (start, input_file)],  shell=True )

Where filename changes iteratively (i'm batch processing and this is the first step). However when i run the script i get for example:

ERROR 4: `200301.h11v09.tif' not recognised as a supported file format.

But when i run the code on 200301.h11v09.tif in terminal it works perfectly. I feel like it's something to do with python string substitution but don't know enough to figure out myself now.

Any ideas?

  • Can you try it with a different filename. It might fail because of the two dots in your filename. – ustroetz Mar 25 '14 at 20:52
  • Makes no difference unfortunately same error with 200301h11v09.tif :( – James Mar 25 '14 at 20:54

Drop the brackets around the first argument to subprocess.call. It's designed to take either a the command string as a single argument, or as a list of arguments that will be separated by a space. Here you are supplying the whole argument in one, so give it as a string, not a list.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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