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

Labeling the points


As you can see from the preceding image, each landmark is simply represented by a colored dot. To make the program more useful, we'll want to display the name of each landmark. This can be done by using the "PAL" labeling engine built into QGIS. Add the following code to your loadMap() method, immediately before the call to self.showVisibleMapLayers():

        p = QgsPalLayerSettings()
        p.readFromLayer(self.landmark_layer)
        p.enabled = True
        p.fieldName = "NAME"
        p.placement = QgsPalLayerSettings.OverPoint
        p.displayAll = True
        p.setDataDefinedProperty(QgsPalLayerSettings.Size,
                                 True, True, "12", "")
        p.quadOffset = QgsPalLayerSettings.QuadrantBelow
        p.yOffset = 1
        p.labelOffsetInMapUnits = False
        p.writeToLayer(self.landmark_layer)

        labelingEngine = QgsPalLabeling()
        self.mapCanvas.mapRenderer().setLabelingEngine(labelingEngine)

This will label each point...