Use subprocess module to run GDAL processes

المشرف العام

Administrator
طاقم الإدارة
I am attempting to write a python script that will reproject & merge a series of .tif files then clip them to the boundaries of a .shp file. I have successfully used the subprocess module to do step 1, but am not sure how to use subprocess to run another second operation. Below is an example of what it might look like if I used subprocess/GDAL to reproject one set of files, then reproject a second set in another folder in the same script. Any ideas on why this won't work?

import os, gdal, subprocess, syscmd = ['gdalwarp', '-t_srs','+proj=longlat +ellps=WGS84','*.tif','new7.tif']cmd2 = ['gdalwarp', '-t_srs','+proj=longlat +ellps=WGS84','newfolder/band4.tif','newfolder/band4_r.tif']proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)stdout,stderr=proc.communicate()proc1 = subprocess1.Popen(cmd2,stdout1=subprocess1.PIPE,stderr1=subprocess1.PIPE)stdout1,stderr1=proc.communicate()exit_code=proc.wait()am new to python and subprocess, thus my code may be way off. Any ideas? Thanks in advance for any help!

Cheers,

Mike



أكثر...
 
أعلى