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 Edit Track map tool


Our next task is to implement the Edit Track action. To do this, we'll take EditTool we defined in Chapter 7, Selecting and Editing Features in a PyQGIS Application, and modify it to work specifically with tracks. Fortunately, we only need to support LineString geometries and can make use of our mixin class, which will simplify the implementation of this new map tool.

Let's start by adding our new class definition to the mapTools.py module, along with the __init__() method:

class EditTrackTool(QgsMapTool, MapToolMixin):
    def __init__(self, canvas, layer, onTrackEdited):
        QgsMapTool.__init__(self, canvas)
        self.onTrackEdited = onTrackEdited
        self.dragging      = False
        self.feature       = None
        self.vertex        = None
        self.setLayer(layer)
        self.setCursor(Qt.CrossCursor)

We now define our canvasPressEvent() method to respond when the user presses the mouse button over our map canvas:

    def canvasPressEvent(self,...