From 2defaff7966e54ea8300273f0566d0428e8a488c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 15 Feb 2018 07:53:37 +1000 Subject: [PATCH] [processing] Much faster random points in polygon by using prepared geometries --- .../plugins/processing/algs/qgis/RandomPointsPolygons.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/plugins/processing/algs/qgis/RandomPointsPolygons.py b/python/plugins/processing/algs/qgis/RandomPointsPolygons.py index e2d73d62a3b..c3f4333b130 100644 --- a/python/plugins/processing/algs/qgis/RandomPointsPolygons.py +++ b/python/plugins/processing/algs/qgis/RandomPointsPolygons.py @@ -136,6 +136,9 @@ class RandomPointsPolygons(QgisAlgorithm): if feedback.isCanceled(): break + if not f.hasGeometry(): + continue + current_progress = total * current feedback.setProgress(current_progress) @@ -147,6 +150,9 @@ class RandomPointsPolygons(QgisAlgorithm): continue fGeom = f.geometry() + engine = QgsGeometry.createGeometryEngine(fGeom.constGet()) + engine.prepareGeometry() + bbox = fGeom.boundingBox() if strategy == 0: pointCount = int(value) @@ -176,7 +182,7 @@ class RandomPointsPolygons(QgisAlgorithm): p = QgsPointXY(rx, ry) geom = QgsGeometry.fromPointXY(p) - if geom.within(fGeom) and \ + if engine.contains(geom.constGet()) and \ vector.checkMinDistance(p, index, minDistance, points): f = QgsFeature(nPoints) f.initAttributes(1)