Skip to content
Permalink
Browse files

Count and report progress based on expected total

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 4, 2018
1 parent 4103614 commit 885ea99a4e85742445c758858f305e0f01d9088b
Showing with 10 additions and 7 deletions.
  1. +10 −7 python/plugins/processing/algs/qgis/RegularPoints.py
@@ -38,12 +38,11 @@
QgsFeature,
QgsWkbTypes,
QgsGeometry,
QgsPointXY,
QgsPoint,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDistance,
QgsProcessingParameterExtent,
QgsProcessingParameterNumber,
QgsProcessingParameterBoolean,
QgsProcessingParameterCrs,
QgsProcessingParameterFeatureSink)
@@ -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

@@ -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.
You can’t perform that action at this time.