from PyQt4.QtCore import *
from PyQt4.QtGui import *
def Symbology():
canvas = qgis.utils.iface.mapCanvas()
layer = qgis.utils.iface.activeLayer()
for feat in layer.getFeatures():
Value = feat['field']
print Value
if Value != '':
featColor = {
Value : ('red',Value ),
}
elif Value == '':
featColor = {
'' : ('green','')
}
ranges = []
for rType, (color, label) in featColor.items():
print rType,(color, label)
symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
symbol.setColor(QColor(color))
category = QgsRendererCategoryV2(rType, symbol, label)
ranges.append(category)
# create the renderer and assign it to a layer
expression = 'field' # field name
renderer = QgsCategorizedSymbolRendererV2(expression, categories)
layer.setRendererV2(renderer)
canvas.zoomToSelected()
layer.removeSelection()
Here i have to set based on the feature value but when i am executing this script it is setting for only one value. I f i want to set colors based on the values how can i do that?
The value contains for example Value = ['x','y',NULL]