Skip to content

Commit

Permalink
Count and report progress based on expected total
Browse files Browse the repository at this point in the history
Algorithm appears to freeze without progress while `extent_engine.intersects(geom.constGet())` returns false.

This keeps the progress bar continuous and smooth, even if the feature ends up not being added.

(noticed this because the algo hangs for 2 mins while processing a large dataset which I think is outside the extent somehow. None of the points going in. No apparent progress.)

(cherry-picked from 93ee062)
  • Loading branch information
jfeldstein authored and nyalldawson committed Aug 16, 2018
1 parent 4103614 commit 885ea99
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions python/plugins/processing/algs/qgis/RegularPoints.py
Expand Up @@ -38,12 +38,11 @@
QgsFeature,
QgsWkbTypes,
QgsGeometry,
QgsPointXY,
QgsPoint,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDistance,
QgsProcessingParameterExtent,
QgsProcessingParameterNumber,
QgsProcessingParameterBoolean,
QgsProcessingParameterCrs,
QgsProcessingParameterFeatureSink)
Expand Down Expand Up @@ -130,6 +129,7 @@ def processAlgorithm(self, parameters, context, feedback):
f.setFields(fields)

count = 0
id = 0
total = 100.0 / (area / pSpacing)
y = extent.yMaximum() - inset

Expand All @@ -144,19 +144,22 @@ def processAlgorithm(self, parameters, context, feedback):
break

if randomize:
geom = QgsGeometry().fromPointXY(QgsPointXY(
geom = QgsGeometry(QgsPoint(
uniform(x - (pSpacing / 2.0), x + (pSpacing / 2.0)),
uniform(y - (pSpacing / 2.0), y + (pSpacing / 2.0))))
else:
geom = QgsGeometry().fromPointXY(QgsPointXY(x, y))
geom = QgsGeometry(QgsPoint(x, y))

if extent_engine.intersects(geom.constGet()):
f.setAttribute('id', count)
f.setAttributes([id])
f.setGeometry(geom)
sink.addFeature(f, QgsFeatureSink.FastInsert)
x += pSpacing
count += 1
feedback.setProgress(int(count * total))
id += 1

count += 1
feedback.setProgress(int(count * total))

y = y - pSpacing

return {self.OUTPUT: dest_id}

0 comments on commit 885ea99

Please sign in to comment.