Skip to content
Permalink
Browse files

[processing] More efficient point count for simplify algorithm

  • Loading branch information
nyalldawson committed Aug 31, 2016
1 parent 73d8544 commit f9e508c566e993e2b9152487a1229504ca6bde15
Showing with 2 additions and 27 deletions.
  1. +2 −27 python/plugins/processing/algs/qgis/SimplifyGeometries.py
@@ -77,9 +77,9 @@ def processAlgorithm(self, progress):
for current, f in enumerate(features):
featGeometry = f.geometry()
attrs = f.attributes()
pointsBefore += self.geomVertexCount(featGeometry)
pointsBefore += featGeometry.geometry().nCoordinates()
newGeometry = featGeometry.simplify(tolerance)
pointsAfter += self.geomVertexCount(newGeometry)
pointsAfter += newGeometry.geometry().nCoordinates()
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributes(attrs)
@@ -90,28 +90,3 @@ def processAlgorithm(self, progress):

ProcessingLog.addToLog(ProcessingLog.LOG_INFO,
self.tr('Simplify: Input geometries have been simplified from %s to %s points' % (pointsBefore, pointsAfter)))

def geomVertexCount(self, geometry):
geomType = geometry.type()

if geomType == QgsWkbTypes.LineGeometry:
if geometry.isMultipart():
pointsList = geometry.asMultiPolyline()
points = sum(pointsList, [])
else:
points = geometry.asPolyline()
return len(points)
elif geomType == QgsWkbTypes.PolygonGeometry:
if geometry.isMultipart():
polylinesList = geometry.asMultiPolygon()
polylines = sum(polylinesList, [])
else:
polylines = geometry.asPolygon()

points = []
for l in polylines:
points.extend(l)

return len(points)
else:
return None

0 comments on commit f9e508c

Please sign in to comment.
You can’t perform that action at this time.