[Qgis-developer] symbolForFeature() does not works?
Minoru Akagi
akaginch at gmail.com
Thu Jul 3 17:54:30 PDT 2014
Hi Alexander,
2014-07-04 0:53 GMT+09:00 Alexander Bruy <alexander.bruy at gmail.com>:
> Hi all,
>
> seems symbolForFeature() method does not works as expected for most
> renderers:
> * QgsSingleSymbolRendererV2 — returns feature symbol
> * QgsCategorizedSymbolRendererV2 — returns None and in debug output
> I have message saying "there are no hashed symbols!!!"
> * QgsGraduatedSymbolRendererV2 — just crashes QGIS
> * QgsRuleBasedRendererV2 — returns None
>
> All tests made with point shapefile. Here is code snipped I used (load vector
> layer and activate it first):
>
> layer = iface.mapCanvas().currentLayer()
> feat = layer.getFeatures().next()
> renderer = layer.rendererV2()
> symbol = renderer.symbolForFeature(feat)
>
> For me this is major issue that makes difficult to develop plugins that works
> with layer symbology (e.g. symbology import/export/conversion)
>
> Anyone confirms? Should I open a ticket?
Matthias Kuhn showed me a workaround
(http://hub.qgis.org/issues/10096#note-1). My code is like this:
# initialize symbol rendering
renderer = QgsMapRenderer()
layer.rendererV2().startRender(renderer.rendererContext(),
layer.pendingFields() if
apiChanged23 else layer)
for f in layer.getFeatures():
symbol = layer.rendererV2().symbolForFeature(f)
print symbol.color().name()
layer.rendererV2().stopRender(renderer.rendererContext())
--
Regards,
Minoru
More information about the Qgis-developer
mailing list