I'm writing a generic script which involves writing shapefiles to a directory which are then merged together. After writing the files out to the Output folder, I'm trying to get the saga:mergeshapeslayers algorithm to merge all the files in the Output folder. I have used the Model Builder and although it is helpful to an extent, I find that it is used for specific purposes whereas I am attempting to make a script for generic purposes.
Code:
##Test=name
##Select_folder=folder
##Result=output vector
import os
import glob
path_1 = Select_folder
path = path_1
os.chdir(path)
def function():
output = glob.glob(path_1 + './*.shp')
x = 0
while output[x]:
for fname in glob.glob("*.shp"):
outputs_1 = processing.runandload("qgis:fieldcalculator", output[x], 'Number', 1, 10, 0, True, 1 , "C:\Users\Me\Desktop\Output\\" + fname)
multiple_0 = glob.glob("*.shp")
x = x + 1
if x + 1 > len(output):
processing.runalg("saga:mergeshapeslayers", output[0], ";".join(multiple_0) , Result)
break
else:
continue
if path_1:
function()
else:
pass
Z?. What does thefunction(Z)serve if it returns nothing ? What is the difference betweenglob.glob(Z + './*.shp')andglob.glob("*.shp")? – gene Jun 10 '14 at 18:18glob.glob(path_1 + './*.shp')defines where the .shp files are; andglob.glob("*.shp")fetches the filenames of the .shp files. Please correct me if I'm mistaken. – Joseph Jun 11 '14 at 11:52