The Find Shortest Path action
This is the last feature of the ForestTrails that we will have to implement. When the user clicks on this toolbar icon, we want to calculate the shortest available path between the given start and end points. Fortunately, the QGIS network analysis library will do the actual calculation for us. All we have to do is run the shortest path calculation on the track layer, build the LineString that corresponds to this shortest path, and display that LineString geometry in our memory-based map layer.
All of this logic will be implemented within the findShortestPath()
method. We'll start our implementation with a bit of housekeeping: if the user unchecks the Find Shortest Path toolbar icon, we clear the shortest path memory layer, switch back to the panning mode, and redraw the map canvas to show the map without the previous path:
def findShortestPath(self): if not self.actionFindShortestPath.isChecked(): self.clearMemoryLayer(self.shortestPathLayer...