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

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