Implementing symbol layers in Python
If the built-in symbol layers aren't flexible enough for your needs, you can implement your own symbol layers using Python. To do this, you create a subclass of the appropriate type of symbol layer (QgsMarkerSymbolLayerV2
, QgsLineSymbolV2
, or QgsFillSymbolV2
) and implement the various drawing methods yourself. For example, here is a simple marker symbol layer that draws a cross for a Point geometry:
class CrossSymbolLayer(QgsMarkerSymbolLayerV2): def __init__(self, length=10.0, width=2.0): QgsMarkerSymbolLayerV2.__init__(self) self.length = length self.width = width def layerType(self): return "Cross" def properties(self): return {'length' : self.length, 'width' : self.width} def clone(self): return CrossSymbolLayer(self.length, self.width) def startRender(self, context): self.pen = QPen() self.pen.setColor(self.color()) self.pen.setWidth(self...