Skip to content

Commit

Permalink
[processing] Much faster random points in polygon by using
Browse files Browse the repository at this point in the history
prepared geometries
  • Loading branch information
nyalldawson committed Feb 14, 2018
1 parent 81aa2f9 commit 2defaff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion python/plugins/processing/algs/qgis/RandomPointsPolygons.py
Expand Up @@ -136,6 +136,9 @@ def processAlgorithm(self, parameters, context, feedback):
if feedback.isCanceled():
break

if not f.hasGeometry():
continue

current_progress = total * current
feedback.setProgress(current_progress)

Expand All @@ -147,6 +150,9 @@ def processAlgorithm(self, parameters, context, feedback):
continue

fGeom = f.geometry()
engine = QgsGeometry.createGeometryEngine(fGeom.constGet())
engine.prepareGeometry()

bbox = fGeom.boundingBox()
if strategy == 0:
pointCount = int(value)
Expand Down Expand Up @@ -176,7 +182,7 @@ def processAlgorithm(self, parameters, context, feedback):

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)
Expand Down

0 comments on commit 2defaff

Please sign in to comment.