I am using QGIS 2.10 (but I've also tried 2.8) to loop through all the shapefiles in a folder (those ending in .shp) and perform a dissolve function on each of them. However, when I run the following code in QGIS it crashes the program. If I run the code outside of QGIS, the QgsGeometryAnalyzer().dissolve function returns 'False'.
Strangely, the same processes work outside of a loop. For example, if I load a shapefile using the QgsVectorLayer function and perform a dissolve using the QgsGeometryAnalyzer().dissolve function everything operates correctly.
Is there something I'm missing here?
import os
from qgis.core import *
from qgis.analysis import *
files = os.listdir('C:/Temp')
for file in files:
if file[-3:] == 'shp':
layer = QgsVectorLayer(file, file[:-4], 'ogr')
QgsGeometryAnalyzer().dissolve(layer, 'C:/Temp/Dissolved/' + file[:-4]+"_dissolved")
*Also, I should note that I've tried to do the same process with GRASS using the v.dissolve command. Unfortunately, this doesn't merge/dissolve polygons that are not overlapping. I need all of the polygons in a shapefile to become one multipart polygon.