[processing] Much faster random points in polygon by using

prepared geometries
This commit is contained in:
Nyall Dawson 2018-02-15 07:53:37 +10:00
parent 81aa2f956e
commit 2defaff796

View File

@ -136,6 +136,9 @@ class RandomPointsPolygons(QgisAlgorithm):
if feedback.isCanceled(): if feedback.isCanceled():
break break
if not f.hasGeometry():
continue
current_progress = total * current current_progress = total * current
feedback.setProgress(current_progress) feedback.setProgress(current_progress)
@ -147,6 +150,9 @@ class RandomPointsPolygons(QgisAlgorithm):
continue continue
fGeom = f.geometry() fGeom = f.geometry()
engine = QgsGeometry.createGeometryEngine(fGeom.constGet())
engine.prepareGeometry()
bbox = fGeom.boundingBox() bbox = fGeom.boundingBox()
if strategy == 0: if strategy == 0:
pointCount = int(value) pointCount = int(value)
@ -176,7 +182,7 @@ class RandomPointsPolygons(QgisAlgorithm):
p = QgsPointXY(rx, ry) p = QgsPointXY(rx, ry)
geom = QgsGeometry.fromPointXY(p) geom = QgsGeometry.fromPointXY(p)
if geom.within(fGeom) and \ if engine.contains(geom.constGet()) and \
vector.checkMinDistance(p, index, minDistance, points): vector.checkMinDistance(p, index, minDistance, points):
f = QgsFeature(nPoints) f = QgsFeature(nPoints)
f.initAttributes(1) f.initAttributes(1)