Skip to content

Commit

Permalink
Merge pull request #1149 from p0cisk/master
Browse files Browse the repository at this point in the history
[processing]Fix "float division by zero" in polygonize algorithm if no
  • Loading branch information
volaya committed Mar 25, 2014
2 parents db235c8 + 02822d4 commit 19da71c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion python/plugins/processing/algs/Polygonize.py 100644 → 100755
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 19da71c

Please sign in to comment.