Code below changes the color of all the selected features based on the last condition it satisfied instead of changing the color of the feature which satisfied the condition.
for f in FEATURES:
total = f['parkeer_approx']
alloted = parking_capacity[f.id()-int(1)]['parking_capacity']
print(total,alloted)
if total == alloted:
print('in red')
iface.mapCanvas().setSelectionColor(QColor("red"))
elif alloted > 0 and alloted < total:
print('in orange')
iface.mapCanvas().setSelectionColor(QColor("yellow"))
else:
print('in green')
iface.mapCanvas().setSelectionColor(QColor("green"))
What I want is to change the color of each selected feature separately based on the conditions defined in the code above.
How can I achieve that?
is_selected()
which checks if the feature is selected. You could set up anif
expression to apply a style if the feature is selected or not. I don't think this function is avialable in QGIS 2 though.