Skip to content
Permalink
Browse files

Merge pull request #1149 from p0cisk/master

[processing]Fix "float division by zero" in polygonize algorithm if no
  • Loading branch information
volaya committed Mar 25, 2014
2 parents db235c8 + 02822d4 commit 19da71cca06efcd56aee64c433e28d9dfbfe067a
Showing with 12 additions and 1 deletion.
  1. +12 −1 python/plugins/processing/algs/Polygonize.py
@@ -66,6 +66,7 @@ def processAlgorithm(self, progress):
allLinesList = []
features = vector.features(vlayer)
current = 0
progress.setInfo('Processing lines...')
total = 40.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
@@ -77,10 +78,19 @@ def processAlgorithm(self, progress):
progress.setPercentage(int(current * total))
progress.setPercentage(40)
allLines = MultiLineString(allLinesList)
allLines = allLines.union(Point(0, 0))
progress.setInfo('Noding lines...')
try:
from shapely.ops import unary_union
allLines = unary_union(allLines)
except ImportError:
allLines = allLines.union(Point(0, 0))
progress.setPercentage(45)
progress.setInfo('Polygonizing...')
polygons = list(polygonize([allLines]))
if not polygons:
raise GeoAlgorithmExecutionException('No polygons were created!')
progress.setPercentage(50)
progress.setInfo('Saving polygons...')
writer = output.getVectorWriter(fields, QGis.WKBPolygon, vlayer.crs())
outFeat = QgsFeature()
current = 0
@@ -93,6 +103,7 @@ def processAlgorithm(self, progress):
writer.addFeature(outFeat)
current += 1
progress.setPercentage(50 + int(current * total))
progress.setInfo('Finished')
del writer

def defineCharacteristics(self):

0 comments on commit 19da71c

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