Graphics Reference
In-Depth Information
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 land-
mark. This can be done by using the "PAL" labeling engine built into QGIS. Add the fol-
lowing 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 on the map. Unfortunately, there are a lot of points, and the res-
ulting map is completely unreadable:
Search WWH ::




Custom Search