[Qgis-developer] Changing symbology setting fro a loaded layer in PyQgis

Martin Dobias wonder.sk at gmail.com
Mon Mar 29 07:32:25 EDT 2010


On Sat, Mar 27, 2010 at 6:48 PM, Marcelo Reyes <reyesmarcelo at gmail.com> wrote:
> [...]
> It is a POINT layer that shows points of 8 different types. Now I would like
> to change the symboly associated with the layer in order to display each
> type in a different color, and if possible using a different icon. Any
> example on how to do this?

This is an example of using single symbol renderer for points, it will
render green circles with red outline:

s=QgsSymbol(QGis.Point)
s.setColor(QColor(255,0,0))
s.setBrush(QBrush(QColor(0,255,0)))
sr=QgsSingleSymbolRenderer(QGis.Point)
sr.addSymbol(s)
layer.setRenderer(sr)

If you need different symbols for different attribute values, you
should use either QgsGraduatedSymbolRenderer or
QgsUniqueValueRenderer. You would need add several symbols (QgsSymbol
instances) for them and assign lower/upper values. See QGIS API
reference for more details about the classes.

Another possibility is, if you're using QGIS 1.4 or development
version, to use new symbology infrastructure. It is described here:
http://www.qgis.org/wiki/Symbology-NG

Regards
Martin


More information about the Qgis-developer mailing list