I have a QGIS layer that represents a set of links and nodes to show the streets of a city and the traffic speeds on each street. I've been trying to write a script so that if I change the speeds in the CSV file (links3.csv) the speeds will automatically update in QGIS. However when I run the code I currently have, then change the file, the entire program freezes and I have to force quit it.
import qgis.utils from PyQt4.QtCore import QFileSystemWatcher myLayer = qgis.utils.iface.activeLayer() def refreshLayer(): myLayer.setCacheImage( None ) myLayer.triggerRepaint() watcher = QFileSystemWatcher() watcher.addPath( '/Users/username/Traffic Speeds/links3.csv' ) watcher.fileChanged.connect( refreshLayer )
What am I doing wrong? I got the code to automatically refresh the layer from here