Skip to content

Commit

Permalink
[processing] More efficient point count for simplify algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 31, 2016
1 parent 73d8544 commit f9e508c
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions python/plugins/processing/algs/qgis/SimplifyGeometries.py
Expand Up @@ -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)
Expand All @@ -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.