Navigation Menu

Skip to content

Commit

Permalink
Better reporting of errors when paths cannot be found, also
Browse files Browse the repository at this point in the history
output point but with no geometry and missing attributes so
that it's clear which points could not be linked
  • Loading branch information
nyalldawson committed Oct 31, 2017
1 parent 36a38f4 commit 4149da0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/qgis/ShortestPathLayerToPoint.py
Expand Up @@ -246,12 +246,18 @@ def processAlgorithm(self, parameters, context, feedback):
break

idxStart = graph.findVertex(snappedPoints[i])

tree, cost = QgsGraphAnalyzer.dijkstra(graph, idxStart, 0)

if tree[idxEnd] == -1:
msg = self.tr('There is no route from start point ({}) to end point ({}).'.format(points[i].toString(), endPoint.toString()))
feedback.setProgressText(msg)
QgsMessageLog.logMessage(msg, self.tr('Processing'), QgsMessageLog.WARNING)
feedback.reportError(msg)
# add feature with no geometry
feat.clearGeometry()
attrs = source_attributes[i]
attrs.append(points[i].toString())
feat.setAttributes(attrs)
sink.addFeature(feat, QgsFeatureSink.FastInsert)
continue

cost = 0.0
Expand Down
Expand Up @@ -250,8 +250,13 @@ def processAlgorithm(self, parameters, context, feedback):

if tree[idxEnd] == -1:
msg = self.tr('There is no route from start point ({}) to end point ({}).'.format(startPoint.toString(), points[i].toString()))
feedback.setProgressText(msg)
QgsMessageLog.logMessage(msg, self.tr('Processing'), QgsMessageLog.WARNING)
feedback.reportError(msg)
# add feature with no geometry
feat.clearGeometry()
attrs = source_attributes[i]
attrs.extend([NULL, points[i].toString()])
feat.setAttributes(attrs)
sink.addFeature(feat, QgsFeatureSink.FastInsert)
continue

cost = 0.0
Expand Down

0 comments on commit 4149da0

Please sign in to comment.