[Qgis-community-team] [Get Feature Color] - How to?
Danilo da Silveira Figueira
danilomalzao at hotmail.com
Thu Sep 10 12:41:45 PDT 2015
I got this,
Map will contain a index to each color used in rendering.
If someone is having the same problem the example code is below:
from PyQt4.QtCore import QVariant
layer = iface.addVectorLayer("estados.shp", "estados", "ogr")
if not layer:
print "Layer failed to load!"
layer.loadSldStyle("estados_Nome.sld")
color = 0
map = {}
for curRule in layer.rendererV2().rootRule().children() :
layer.dataProvider().setSubsetString(curRule.filterExpression())
color +=1
for curFeature in layer.dataProvider().getFeatures():
map[curFeature.id()] = color
layer.dataProvider().setSubsetString("")
map
2015-09-10 14:14 GMT-03:00 Danilo da Silveira Figueira <
danilomalzao at hotmail.com>:
> Hello All,
>
> I'm stuck here, any help would be appreciated.
> I have to create a attribute column with the respective color used in
> renderer of this attribute, i am using the QgsVectorLayer
> <http://qgis.org/api/classQgsVectorLayer.html>.loadSldStyle that creates
> a QgsRuleBasedRendererV2
> <http://qgis.org/api/classQgsRuleBasedRendererV2.html> but
> the symbolsForFeature is returning empty.
> With the symbol i could get the color and finish my job, but the
> symbolsList is always empty.
>
> My Try:
>
> layer = QgsVectorLayer("estados.shp", "estados", "ogr")
> if not layer:
> print "Layer failed to load!"
>
> layer.loadSldStyle("estados_Nome.sld")
> layer.triggerRepaint()
> for curFeature in layer.dataProvider().getFeatures():
> layer.rendererV2().symbolsForFeature(curFeature)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-community-team/attachments/20150910/a69c3069/attachment.html>
More information about the Qgis-community-team
mailing list