Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

##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 '14 at 16:25
up vote 1 down vote accepted

Found a method which helped me and hopefully others:

##Merged_Layer=output vector

import os
import glob

input = processing.getObject(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 '14 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 '14 at 9:14

Your Answer


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.