Graphics Reference
In-Depth Information
tiedPoints = director.makeGraph(builder,
[self.curStartPt,
self.curEndPt])
graph = builder.graph()
startPt = tiedPoints[0]
endPt = tiedPoints[1]
startVertex = graph.findVertex(startPt)
tree = QgsGraphAnalyzer.shortestTree(graph,
startVertex, 0)
startVertex = tree.findVertex(startPt)
endVertex = tree.findVertex(endPt)
if endVertex == -1:
QMessageBox.information(self.window,
"Not Found",
"No path found.")
return
points = []
while startVertex != endVertex:
incomingEdges = tree.vertex(endVertex).inArc()
if len(incomingEdges) == 0:
break
edge = tree.arc(incomingEdges[0])
points.insert(0,
tree.vertex(edge.inVertex()).point())
endVertex = edge.outVertex()
points.insert(0, startPt)
The preceding code was copied from the PyQGIS cookbook with some changes in vari-
able names to make the meaning clearer. At the end, points will be a list of QgsPoint
objects defining the LineString geometry that connects the starting point to the ending
point. The most interesting part of this method is the following:
Search WWH ::




Custom Search