mardi 3 mars 2015

Why this Python script only works once on QGIS?


So i have this script to change the color of some specific features(lines) using categories in a vector layer. When i import the script the console in the first time through the console it works just fine BUT (while qgis is open) when i edit the script and change the color of some category to 'red' instead of the previous 'green' and then import script again, it doesnt show the changes, the lines have the same color like before.Here's the script and some images:



from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import iface

def change_color():
active_layer = iface.activeLayer()

pipeline = [["1", "green"],["2","red"],
["3","green"],["4","green"],["5","green"]]

categories=[]

for label,color in pipeline:
symbol = QgsSymbolV2.defaultSymbol(active_layer.geometryType())
symbol.setColor(QColor(color))
category = QgsRendererCategoryV2(int(label), symbol, label)
categories.append(category)

expression = 'id'
renderer = QgsCategorizedSymbolRendererV2(expression, categories)
active_layer.setRendererV2(renderer)
active_layer.setCacheImage(None)
iface.mapCanvas().refresh()
iface.legendInterface().refreshLayerSymbology(active_layer)

change_color()


enter image description here Now lets say for example that i edit script and change pipeline to: pipeline = [["1", "green"],["2","red"], ["3","red"],["4","green"],["5","red"]]


and run script again. Then it should show 3 red lines instead of 1!But it doesnt!!!Hope i was clear enough. Thanks in advance(btw im kinda noob and not even close to a developer)





Aucun commentaire:

Enregistrer un commentaire