Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like the user to select a folder via the interface in which all the vector shapefiles inside that folder would be merged.

I have been using the Model Builder and looking at example scripts and tried to incorporate simple commands into my own script. The following code is incorrect but any guidance would be appreciative:

##Test=name
##input=folder
##merge=output vector

outputs_0=processing.runalg("qgis:mergevectorlayers", input, None)

I have looked at Merge scripts from the Processing and SAGA plugins, but I was wondering if it's possible to do something similar in just one or two lines of code?

share|improve this question
    
If you use the model builder, you don't need to write any code manually. Instead it seems like you are trying to write a new Processing script. Could you please clarify your question? –  underdark May 21 at 16:25

1 Answer 1

up vote 0 down vote accepted

Found a method which helped me and hopefully others:

##Test=name
##Select_Directory=folder
##Merged_Layer=output vector

import os
import glob

input = processing.getObject(Select_Directory)
os.chdir(Select_Directory)
output = glob.glob('./*.shp')
Layer_0 = output[0]

processing.runalg("saga:mergeshapeslayers",  Layer_0, ";".join(output), Merged_Layer)    
share|improve this answer
    
You wrote a new scrip which does exactly the same thing a saga:mergeshapeslayer? Also, input is assigned but never used ... –  underdark May 21 at 16:28
    
Apologies for being unclear - my intention was to create a custom script where a directory can be selected instead of seperate files as in saga:mergeshapeslayer. This is then followed by other various functions. As you suggested, I will use the Model Builder more often, thank you. –  Joseph May 22 at 9:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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