Graphics Reference
In-Depth Information
clone() : This method should return a copy of the symbol layer. Since we have
defined our properties as parameters to the __init__ method, implementing
this method simply involves creating a new instance of the class and copying the
properties from the current symbol layer to the new instance.
startRender() : This method is called before the first feature in the map layer
is rendered. This can be used to define any objects that will be required to draw
the feature. Rather than creating these objects each time, it is more efficient (and
therefore faster) to create them only once to render all the features. In this ex-
ample, we create the QPen object that we will use to draw the Point geometries.
stopRender() : This method is called after the last feature has been rendered.
This can be used to release the objects created by the startRender() method.
renderPoint() : This is where all the work is done for drawing point geomet-
ries. As you can see, this method takes two parameters: the point at which to draw
the symbol, and the rendering context (an instance of QgsSymbolV2Render-
Context ) to use for drawing the symbol.
• The rendering context provides various methods to access the feature being dis-
played, as well as information about the rendering operation, the current scale
factor, and so on. Most importantly, it allows you to access the PyQt QPainter
object required to actually draw the symbol on the screen.
The renderPoint() method is only used for symbol layers that draw point geomet-
ries. For line geometries, you should implement the renderPolyline() method,
which has the following signature:
def renderPolyline(self, points, context):
The points parameter will be a QPolygonF object that contains the various points that
make up the LineString, and context will be the rendering context to use to draw the
geometry.
If your symbol layer is intended to work with polygons, you should implement the
renderPolygon() method, which looks like this:
def renderPolygon(self, outline, rings, context):
Here, outline is a QPolygonF object that contains the points that make up the exteri-
or of the polygon, and rings is a list of QPolygonF objects that define the interior
Search WWH ::




Custom Search