Skip to content

Commit 885ea99

Browse files
jfeldsteinnyalldawson
authored andcommitted
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)
1 parent 4103614 commit 885ea99

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

python/plugins/processing/algs/qgis/RegularPoints.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@
3838
QgsFeature,
3939
QgsWkbTypes,
4040
QgsGeometry,
41-
QgsPointXY,
41+
QgsPoint,
4242
QgsProcessing,
4343
QgsProcessingException,
4444
QgsProcessingParameterDistance,
4545
QgsProcessingParameterExtent,
46-
QgsProcessingParameterNumber,
4746
QgsProcessingParameterBoolean,
4847
QgsProcessingParameterCrs,
4948
QgsProcessingParameterFeatureSink)
@@ -130,6 +129,7 @@ def processAlgorithm(self, parameters, context, feedback):
130129
f.setFields(fields)
131130

132131
count = 0
132+
id = 0
133133
total = 100.0 / (area / pSpacing)
134134
y = extent.yMaximum() - inset
135135

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

146146
if randomize:
147-
geom = QgsGeometry().fromPointXY(QgsPointXY(
147+
geom = QgsGeometry(QgsPoint(
148148
uniform(x - (pSpacing / 2.0), x + (pSpacing / 2.0)),
149149
uniform(y - (pSpacing / 2.0), y + (pSpacing / 2.0))))
150150
else:
151-
geom = QgsGeometry().fromPointXY(QgsPointXY(x, y))
151+
geom = QgsGeometry(QgsPoint(x, y))
152152

153153
if extent_engine.intersects(geom.constGet()):
154-
f.setAttribute('id', count)
154+
f.setAttributes([id])
155155
f.setGeometry(geom)
156156
sink.addFeature(f, QgsFeatureSink.FastInsert)
157157
x += pSpacing
158-
count += 1
159-
feedback.setProgress(int(count * total))
158+
id += 1
159+
160+
count += 1
161+
feedback.setProgress(int(count * total))
162+
160163
y = y - pSpacing
161164

162165
return {self.OUTPUT: dest_id}

0 commit comments

Comments
 (0)