7

I want to automate a periodic refresh of the QGIS map canvas with updated shapefiles. A Python plugin or console script does not allow the map to update until the script terminates. Is there a way to force a map refresh in a running plugin or script, or is a stand-alone app required?

Using v1.7.4 now but could migrate to newer version.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 19, 2014 at 16:26

1 Answer 1

4

You can use the python threading library to run a function periodically:

I have used the following statements to remove a set of graphics after 3 seconds:

from threading import Timer
Timer( 3, self._clearGraphicLayer, ()).start()
def _clearGraphicLayer(self):
 for graphic in self.graphicsLayer: 
 self.iface.mapCanvas().scene().removeItem(graphic)
 self.iface.mapCanvas().refresh()
 self.graphicsLayer = []

And if needed you can have the callback function restart the timer if a certain condition is not met. But look out if you use this module wrong you can crash the entire application.

More info: https://docs.python.org/2/library/threading.html

answered Aug 19, 2014 at 17:49
1
  • You may want to consider to update to QGIS 2.4 which has improved considerably concerning thread-safety when iterating layer data. Commented Aug 20, 2014 at 10:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.