Working with custom map layers
Instead of using a standard map layer with a data provider, features, symbols, and so on, you can implement your own custom map layer entirely in Python. Custom map layers are generally used to draw specific data that is too complicated to represent as vector format data, or to draw special visual features such as a grid or a watermark onto the map.
Custom map layers are implemented by subclassing the QgsPluginLayer
class. The process is actually very simple, though you will need to translate between map and device coordinates so that the items you draw in your Python layer match up with the features drawn in the other layers within your canvas.
Note
Don't get confused by the name; you don't have to write a QGIS plugin to create your own QgsPluginLayer
subclass.
Let's see how we can create our own subclass of QgsPluginLayer
. We're going to create a simple grid that can appear as a layer within the map. Let's start by defining the QgsPluginLayer
subclass itself...