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 Get Info map tool


When the user clicks on the Get Info item in the toolbar, we will activate a custom map tool that lets the user click on a track to display and edit the attributes for that track. Let's walk through this implementation one step at a time, starting with the GetInfoTool class itself. Add the following to your mapTools.py module:

class GetInfoTool(QgsMapTool, MapToolMixin):
    def __init__(self, canvas, layer, onGetInfo):
        QgsMapTool.__init__(self, canvas)
        self.onGetInfo = onGetInfo
        self.setLayer(layer)
        self.setCursor(Qt.WhatsThisCursor)

    def canvasReleaseEvent(self, event):
        if event.button() != Qt.LeftButton: return
        feature = self.findFeatureAt(event.pos())
        if feature != None:
            self.onGetInfo(feature)

This map tool calls the onGetInfo() method (which is passed as a parameter to the map tool's initializer) when the user clicks on a track. Let's now use this map tool within our program by adding the following...