Saturday, 12 September 2015

qgis - How to determine when the map has finished rendering


I have written a few functions to compare QGIS performance to MapInfo. Most of them involve doing some analysis then dumping the results on the map, as such the process would be considered 'finished' when the map has finished refreshing/rendering. I believe in this context refreshing/rendering are pretty much the same thing?



I've had a look around the documentation and have found references to (all under QgsMapCanvas class) renderStarting(), renderComplete(QPainter), mapCanvasRefreshed(). These are all 'signals', but I'm not sure how to use them (shame there are no examples in the documentation). Could anyone give me an example? Or is there a better approach? The important thing is to get an end-time when the map has finished rendering



Answer



Signal can be emited by an object. Ex. your canvas:


canvas = iface.mapCanvas()
custom_canvas = QgsMapCanvas() # if you want to create new canvas instead of this from main window

Canvas can emitt a signal renderComplete after rendering is complete, mapCanvasRefreshed after you refresh this canvas.


So you can connect this signal to the proper function and do something:


canvas.mapCanvasRefreshed.connect(custom_function)


Where the custom_function is simply:


def custom_function():
# do something

Read more about signals and slots in the documentation: http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html


Or in this tutorial: http://www.tutorialspoint.com/pyqt/pyqt_signals_and_slots.htm


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...