Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Mapping Applications with QGIS

You're reading from   Building Mapping Applications with QGIS Create your own sophisticated applications to analyze and display geospatial information using QGIS and Python

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher Packt
ISBN-13 9781783984664
Length 264 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Erik Westra Erik Westra
Author Profile Icon Erik Westra
Erik Westra
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with QGIS FREE CHAPTER 2. The QGIS Python Console 3. Learning the QGIS Python API 4. Creating QGIS Plugins 5. Using QGIS in an External Application 6. Mastering the QGIS Python API 7. Selecting and Editing Features in a PyQGIS Application 8. Building a Complete Mapping Application using Python and QGIS 9. Completing the ForestTrails Application 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)
       ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image