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
About the Author
About the Reviewers
Free Chapter
Getting Started with QGIS

Working with selections

The vector layer class, QgsVectorLayer, includes support for keeping track of the user's current selection. Doing this is relatively straightforward: there are methods that set and alter the selection, as well as retrieve the selected features. When features are selected, they are visually highlighted on the screen so that the user can see what has been selected.


If you create your own custom symbol layer, you will need to handle the highlighting of the selected features yourself. We saw how to do this in Chapter 6, Mastering the QGIS Python API, in the section titled Implementing symbol layers in Python.

While there are several ways in which the user can select features, the most straightforward way is to click on them. This can be implemented by using a simple map tool, for example:

class SelectTool(QgsMapToolIdentify):
    def __init__(self, window):
        QgsMapToolIdentify.__init__(self, window.mapCanvas)
        self.window = window