mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-27 00:07:16 -05:00
[processing] Misc fixes and improvements to Random Points in Polygons
- Fix missing format call for string when calculated number of points is 0 - Fix incorrect progress reports which were spamming the dialog and causing UI hangs, and slow algorithm execution
This commit is contained in:
parent
e0cf578096
commit
81aa2f956e
@ -131,10 +131,14 @@ class RandomPointsPolygons(QgisAlgorithm):
|
|||||||
da.setEllipsoid(context.project().ellipsoid())
|
da.setEllipsoid(context.project().ellipsoid())
|
||||||
|
|
||||||
total = 100.0 / source.featureCount() if source.featureCount() else 0
|
total = 100.0 / source.featureCount() if source.featureCount() else 0
|
||||||
|
current_progress = 0
|
||||||
for current, f in enumerate(source.getFeatures()):
|
for current, f in enumerate(source.getFeatures()):
|
||||||
if feedback.isCanceled():
|
if feedback.isCanceled():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
current_progress = total * current
|
||||||
|
feedback.setProgress(current_progress)
|
||||||
|
|
||||||
expressionContext.setFeature(f)
|
expressionContext.setFeature(f)
|
||||||
value = expression.evaluate(expressionContext)
|
value = expression.evaluate(expressionContext)
|
||||||
if expression.hasEvalError():
|
if expression.hasEvalError():
|
||||||
@ -150,7 +154,7 @@ class RandomPointsPolygons(QgisAlgorithm):
|
|||||||
pointCount = int(round(value * da.measureArea(fGeom)))
|
pointCount = int(round(value * da.measureArea(fGeom)))
|
||||||
|
|
||||||
if pointCount == 0:
|
if pointCount == 0:
|
||||||
feedback.pushInfo("Skip feature {} as number of points for it is 0.")
|
feedback.pushInfo("Skip feature {} as number of points for it is 0.".format(f.id()))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
index = QgsSpatialIndex()
|
index = QgsSpatialIndex()
|
||||||
@ -159,7 +163,7 @@ class RandomPointsPolygons(QgisAlgorithm):
|
|||||||
nPoints = 0
|
nPoints = 0
|
||||||
nIterations = 0
|
nIterations = 0
|
||||||
maxIterations = pointCount * 200
|
maxIterations = pointCount * 200
|
||||||
total = 100.0 / pointCount if pointCount else 1
|
feature_total = total / pointCount if pointCount else 1
|
||||||
|
|
||||||
random.seed()
|
random.seed()
|
||||||
|
|
||||||
@ -183,13 +187,13 @@ class RandomPointsPolygons(QgisAlgorithm):
|
|||||||
index.insertFeature(f)
|
index.insertFeature(f)
|
||||||
points[nPoints] = p
|
points[nPoints] = p
|
||||||
nPoints += 1
|
nPoints += 1
|
||||||
feedback.setProgress(int(nPoints * total))
|
feedback.setProgress(current_progress + int(nPoints * feature_total))
|
||||||
nIterations += 1
|
nIterations += 1
|
||||||
|
|
||||||
if nPoints < pointCount:
|
if nPoints < pointCount:
|
||||||
feedback.pushInfo(self.tr('Could not generate requested number of random '
|
feedback.pushInfo(self.tr('Could not generate requested number of random '
|
||||||
'points. Maximum number of attempts exceeded.'))
|
'points. Maximum number of attempts exceeded.'))
|
||||||
|
|
||||||
feedback.setProgress(0)
|
feedback.setProgress(100)
|
||||||
|
|
||||||
return {self.OUTPUT: dest_id}
|
return {self.OUTPUT: dest_id}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user