Skip to content
Permalink
Browse files

[processing] Speed up dissolve when not using fields

  • Loading branch information
nyalldawson committed Oct 17, 2016
1 parent a05b610 commit 688d1a5eba225b07cfbe707b19756683c9a46deb
Showing with 32 additions and 33 deletions.
  1. +32 −33 python/plugins/processing/algs/qgis/Dissolve.py
@@ -84,47 +84,46 @@ def processAlgorithm(self, progress):

if not useField:
first = True
# we dissolve geometries in blocks using unaryUnion
geom_queue = []
for current, inFeat in enumerate(features):
progress.setPercentage(int(current * total))
if first:
attrs = inFeat.attributes()
tmpInGeom = inFeat.geometry()
if tmpInGeom.isEmpty() or tmpInGeom.isGeosEmpty():
continue
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ')
+ error.what())
continue
outFeat.setGeometry(tmpInGeom)
outFeat.setAttributes(inFeat.attributes())
first = False
else:
tmpInGeom = inFeat.geometry()
if tmpInGeom.isEmpty() or tmpInGeom.isGeosEmpty():
continue
tmpOutGeom = outFeat.geometry()
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry()'
'error:One or more input'
'features have invalid '
'geometry: ')
+ error.what())
continue

tmpInGeom = inFeat.geometry()
if tmpInGeom.isEmpty() or tmpInGeom.isGeosEmpty():
continue

errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry()'
'error: One or more '
'input features have '
'invalid geometry: ')
+ error.what())
continue

geom_queue.append(tmpInGeom)

if len(geom_queue) > 10000:
# queue too long, combine it
try:
tmpOutGeom = QgsGeometry(tmpOutGeom.combine(tmpInGeom))
outFeat.setGeometry(tmpOutGeom)
temp_output_geometry = QgsGeometry.unaryUnion(geom_queue)
geom_queue = [temp_output_geometry]
except:
raise GeoAlgorithmExecutionException(
self.tr('Geometry exception while dissolving'))
outFeat.setAttributes(attrs)

try:
outFeat.setGeometry(QgsGeometry.unaryUnion(geom_queue))
except:
raise GeoAlgorithmExecutionException(
self.tr('Geometry exception while dissolving'))

writer.addFeature(outFeat)
else:
field_indexes = [vlayerA.fields().lookupField(f) for f in field_names.split(';')]

0 comments on commit 688d1a5

Please sign in to comment.
You can’t perform that action at this time.