Skip to content

Commit 19da71c

Browse files
committedMar 25, 2014
Merge pull request #1149 from p0cisk/master
[processing]Fix "float division by zero" in polygonize algorithm if no
2 parents db235c8 + 02822d4 commit 19da71c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎python/plugins/processing/algs/Polygonize.py

100644100755
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def processAlgorithm(self, progress):
6666
allLinesList = []
6767
features = vector.features(vlayer)
6868
current = 0
69+
progress.setInfo('Processing lines...')
6970
total = 40.0 / float(len(features))
7071
for inFeat in features:
7172
inGeom = inFeat.geometry()
@@ -77,10 +78,19 @@ def processAlgorithm(self, progress):
7778
progress.setPercentage(int(current * total))
7879
progress.setPercentage(40)
7980
allLines = MultiLineString(allLinesList)
80-
allLines = allLines.union(Point(0, 0))
81+
progress.setInfo('Noding lines...')
82+
try:
83+
from shapely.ops import unary_union
84+
allLines = unary_union(allLines)
85+
except ImportError:
86+
allLines = allLines.union(Point(0, 0))
8187
progress.setPercentage(45)
88+
progress.setInfo('Polygonizing...')
8289
polygons = list(polygonize([allLines]))
90+
if not polygons:
91+
raise GeoAlgorithmExecutionException('No polygons were created!')
8392
progress.setPercentage(50)
93+
progress.setInfo('Saving polygons...')
8494
writer = output.getVectorWriter(fields, QGis.WKBPolygon, vlayer.crs())
8595
outFeat = QgsFeature()
8696
current = 0
@@ -93,6 +103,7 @@ def processAlgorithm(self, progress):
93103
writer.addFeature(outFeat)
94104
current += 1
95105
progress.setPercentage(50 + int(current * total))
106+
progress.setInfo('Finished')
96107
del writer
97108

98109
def defineCharacteristics(self):

0 commit comments

Comments
 (0)
Please sign in to comment.