[Qgis-community-team] [Get Feature Color] - How to?

Otto Dassau dassau at gbd-consult.de
Fri Sep 11 09:47:50 PDT 2015


Dear Danilo,

please send your email to the qgis developer list. This community-team list
is for organizing community related issues.

QGIS Dev:
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Regards,
Otto

Am Thu, 10 Sep 2015 16:41:45 -0300
schrieb Danilo da Silveira Figueira <danilomalzao at hotmail.com>:

> 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)
> >
> >


-- 
Geoinformatikbüro Dassau GmbH 
Rethelstrasse 153
D - 40237 Düsseldorf
Tel: +49-211-69937750
Fax: +49-211-69937751
Mobile  +49-171-4687540
http://www.gbd-consult.de

Registergericht: Amtsgericht Düsseldorf, HR B 74022
Geschäftsführer: Otto Dassau

Member of the QGIS Project Steering Committee


More information about the Qgis-community-team mailing list