Skip to content

Commit

Permalink
Fix some possible exceptions in topocolor alg
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent a056e24 commit 913bf64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/plugins/processing/algs/qgis/TopoColors.py
Expand Up @@ -112,6 +112,9 @@ def processAlgorithm(self, parameters, context, feedback):
feedback=feedback,
min_colors=min_colors)

if len(feature_colors) == 0:
return {self.OUTPUT: dest_id}

max_colors = max(feature_colors.values())
feedback.pushInfo(self.tr('{} colors required').format(max_colors))

Expand Down Expand Up @@ -146,7 +149,7 @@ def compute_graph(features, feedback, create_id_graph=False, min_distance=0):
# skip features without geometry
features_with_geometry = {f_id: f for (f_id, f) in features.items() if f.hasGeometry()}

total = 70.0 / len(features_with_geometry)
total = 70.0 / len(features_with_geometry) if features_with_geometry else 1
index = QgsSpatialIndex()

i = 0
Expand Down Expand Up @@ -211,7 +214,7 @@ def balanced(features, graph, feedback, balance=0, min_colors=4):
color_counts[c] = 0
color_areas[c] = 0

total = 10.0 / len(sorted_by_count)
total = 10.0 / len(sorted_by_count) if sorted_by_count else 1
i = 0

for (feature_id, n) in sorted_by_count:
Expand Down

0 comments on commit 913bf64

Please sign in to comment.