Wednesday, 4 May 2016

Calling Gdal contour from python/ipython


Hello I am trying to patch process a folder full of ASCs to contours using Gdal from python. here is my code;


import os 
import glob

PATH1 = raw_input("folder containing ASCs path please:")



inputlistB = []


for filename in glob.glob(os.path.join(PATH1, '*h_Max.ASC')):
print filename
inputlistB.append(filename)

print inputlistB


for filepath in inputlistB:
src = filepath
dst = filepath+'b.shp'
os.system('gdalcontour -fl -888 -inodata -f "ESRI Shapefile "' + src + " " + dst)

The ipython console returns this;



folder containing ASCs path please:C:\D\OUT


C:\D\OUT\Wray_0010F_012_h_Max.asc C:\D\OUT\Wray_0020F_012_h_Max.asc


C:\D\OUT\Wray_0030F_012_h_Max.asc



['C:\D\OUT\Wray_0010F_012_h_Max.asc',


'C:\D\OUT\Wray_0020F_012_h_Max.asc',


'C:\D\OUT\Wray_0030F_012_h_Max.asc']



showing that the inputlist functions as intended. However no new gis layers are generated in my target folder. If I take the statement ran by os.system and copy it with file paths into command line, it works. Though it does crash after producing the shapefile. If I just run the final line of the for loop os.system(... the Ipython console simply returns :1


Any idea why gdal would crash after producing a shapefile / successfully running?


Any ideas as to why my code does not produce any results despite no python errors?


Any alternative / better solutions to this problem?


also I use the file path input and loop in a lot of programs, feel free to steal it if this is news to you.




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...