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

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)")
        rule.setScaleMinDenom(0)
        rule.setScaleMaxDenom(99999999)
       ...