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

Filtering the landmarks

The reason our labels are unreadable is because there are too many landmarks being displayed. However, not all landmarks are relevant at all zoom levels—we want to hide landmarks that are too small to be useful when the map is zoomed out, while still showing these landmarks when the user zooms in. To do this, we'll use a QgsRuleBasedRendererV2 object and make use of the SCALERANK attribute to selectively hide features that are too small for the current zoom level.

Add the following code to your loadMap() method, before the call to self.showVisibleMapLayers():

        symbol = QgsSymbolV2.defaultSymbol(self.landmark_layer.geometryType())
        renderer = QgsRuleBasedRendererV2(symbol)
        root_rule = renderer.rootRule()
        default_rule = root_rule.children()[0]

        rule = default_rule.clone()
        rule.setFilterExpression("(SCALERANK >= 0) and (SCALERANK <= 1)")