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...