QGIS crashing/failing when dissolving multiple shapefiles in a Python loop

المشرف العام

Administrator
طاقم الإدارة
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.

This should be a very simple task and I've already spent far too long trying to figure this out on my own. Is there something I'm missing here? Any help would be greatly appreciated. Thanks!

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



أكثر...
 
أعلى