[Qgis-developer] symbol levels with rule based rendering

Mayeul Kauffmann mayeul.kauffmann at free.fr
Wed Dec 22 20:31:50 EST 2010


Dear list members,
I would highly value some advice with some coding problem I facewith
rule-based rendering.

I am preparing a patch and I have made extensive additions to many parts
of the code to support some useful features to render map with complex
symbology grammar (see http://trac.osgeo.org/qgis/ticket/3222 for a
discussion). Still, I have problems with the symbol levels. I would like
to enable symbol levels when several rules are matched. It would be
useful when a feature (specially highways) should be represented with a
combination of symbols. For instance, a road can be on a bridge, under a
tunnel [with transparent tunnel symbol], in construction, bordered with
trees, have restricted access, be a one-way road, etc. In many cases, it
is possible to simply combine the symbols, e.g. one symbol for the road
itself and another one for the bridge "around" it, and an arrow for
one-ways. It would be possible to use only one rule for all highways
(except motorways if shown with wider symbol). If we have 30 types of
ways and 5 types of additional symbols (bridge, etc), we could then show
many tags combinations with only 30+5=35 rules instead of 30*5=150.
(Imagine if you add 10 scale-based rules: you got 1500 combinations!!).

For the implementation, I modified the symbolForFeature function in
src/core/symbology-ng/qgsrulebasedrendererv2.cpp


Here is what I'm trying to do: For the first matched rule for a given
feature, the code makes a copy of the rule's symbol. If other rules are
matched, it merges the layers of the additional matched rule with the
symbol(s) of previously matched rule(s). It also merges the information
on symbol levels.

Tests on rendering on small areas (with features matched by 2 rules)
works partially:

    * the symbols are correctly merged. A new symbol is created and
displayed, based on the symbology and levels of the matching rules 8-)
    * However, it modifies the symbol associated with the first matched
rule and shown in the style sheet (if you open the layer properties, you
see that the symbol has been permanently modified): the 1st matched rule
is now represented by a combination of the 2 original symbols. This
change is saved permanently in the Layer Properties. Similarly for
symbol levels. 8-(
    * it crashes very often 8-( 

I've pasted my draft code here:
http://trac.osgeo.org/qgis/ticket/3222#comment:7


I'm sure there are several incorrect thinks here. Anyone could help?
Thanks and Merry Christmas!
Mayeul 



More information about the Qgis-developer mailing list