O'Reilly logo

Building Mapping Applications with QGIS by Erik Westra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required