Skip to content

Commit

Permalink
[processing] Speed up dissolve when not using fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 17, 2016
1 parent a05b610 commit 688d1a5
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions python/plugins/processing/algs/qgis/Dissolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(';')]
Expand Down

0 comments on commit 688d1a5

Please sign in to comment.