[Qgis-developer] Python access to Symbology-ng

Martin Dobias wonder.sk at gmail.com
Tue Dec 1 17:30:52 EST 2009

Hi Dane

On Tue, Dec 1, 2009 at 10:09 PM, Dane Springmeyer <blake at hailmail.net> wrote:
> Martin,
> Using the new symbology/rendererV2 from python how do you get access to the
> classification value and its upperValue/LowerValue?

For categorized symbol renderer use categories() to get list of
QgsRendererCategoryV2 instances. Then use category's value(), symbol()
and label() methods.
For graduated symbol renderer use ranges() to get list of
QgsRendererRangeV2 instances. Then upperValue(), lowerValue() etc.

> layer.renderverV2() returns a 'QgsFeatureRendererV2', whose type() returns
> the string name of a specific renderer, like 'categorizedSymbol' (is that
> the same as the old 'Graduated Symbol'?

"categorizedSymbol" renderer is equal to unique symbol renderer
"graduatedSymbol" renderer is equal to older grad. symbol renderer
there's no equivalent for continuous symbol renderer - graduated
symbol renderer can be used instead

> But, how do you get that specific renderer object?

Ah, it returns always QgsFeatureRendererV2 instance? Maybe I've
forgotten to add conversions to python bindings...

> Also, I can't figure out how to get upper/lower value from either
> rendererV2.symbols() or their symbolLayer(s).

symbols() method is actually designed to be used when overriding
symbol layers rendering order (aka symbol levels).
As stated above, you should use categories() or ranges() methods,
depending on the renderer type.

> And I can't see the the classification info in the renderer like I used to
> do be able to get with the normal renderer:
> idx = layer.renderer().classificationAttributes()[0]
> class_field = layer.dataProvider().fields()[idx]

There's classAttribute() method returning attribute's name used for
classification - both for categorized and graduated symbol renderer.

> Pointers __greatly__ appreciated.
> Lastly, it appears like the docs are not working for symbology-ng:
> http://doc.qgis.org/head/search.php?query=symbology-ng

Seems like the classes are not tagged to be included in the docs. I'll
take a look at it.


More information about the Qgis-developer mailing list