Book Image

Building Mapping Applications with QGIS

By : Erik Westra
Book Image

Building Mapping Applications with QGIS

By: Erik Westra

Overview of this book

Table of Contents (16 chapters)
Building Mapping Applications with QGIS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with QGIS
Index

The Set Start Point and Set End Point actions


The Set Start Point and Set End Point toolbar actions allow the user to set the start and end points in order to calculate the shortest path between these two points. To implement these actions, we're going to need a new map tool that lets the user click on a track vertex to select the starting or ending points.

Note

By positioning the start point and the end point on vertices, we guarantee that the points lie on a track's LineString. We could theoretically be more sophisticated and snap the starting and ending points to anywhere along a track segment, but that's more work, and we're trying to keep the implementation simple.

Go back to the mapTools.py module and add the following class definition to this file:

class SelectVertexTool(QgsMapTool, MapToolMixin):
    def __init__(self, canvas, trackLayer, onVertexSelected):
        QgsMapTool.__init__(self, canvas)
        self.onVertexSelected = onVertexSelected
        self.setLayer(trackLayer)
 ...