TransWikia.com

Could a QGIS plug-in conceivably save and restore the main-window geometry of any project?

Geographic Information Systems Asked by quagmire on September 4, 2021

With respect to this:
Restoring the exact original situation of a spatial bookmark?
and this:
How to Resize the Qgis Main Window from python

Q. Could a plug-in conceivably save the current state of the main QGIS window so that it could be restored later prior to navigating to a saved spatial bookmark?

It would make it much easier to add and print new layers in old projects which would be guaranteed to line up with previously printed layers. (I know that layers would align in QGIS, but I refer to the printed-out images registering correctly.)

The question could be replaced with:
Q. If I have saved a spatial bookmark for a project, how can I add a layer to that project that will be guaranteed to align with layers printed earlier?

(I had the sense from the first reference that it was not possible to completely, automatically, reconstruct the earlier window geometry at a later point. Indeed, I’ve now tried it and found the edge-positioning of the window to be too coarse to get perfect reconstruction.)

One Answer

Thank you Michael. I didn't see this until after I'd spent the better part of an interesting day tooling through QGIS PyGIS documentation where I discovered the QgsMapCanvas template and the Python console.

I'm not a Python programmer, but thought I might be able to use the console to get and set the window (known as "canvas") size.

My hope is that by collecting some of the likely important pieces here, a QGIS plugin author will be inspired to take 5 minutes and write something to supply the missing links to the Spatial Bookmark tool. (It seems crazy that the Spatial Bookmark doesn't store canvas parameters in the xml file it creates with each bookmark. That would enable not just the map extents, but the environment in which printing was done to be re-created exactly as well.)

What I found and played with in Plugins->Python Console:

>>> canvas = qgis.utils.iface.mapCanvas() // shorthand to curr. canvas
>>> canvas.size()
PyQt5.QtCore.QSize(1205, 394)  

>>> canvas.center() // surprised to see UTM coords, since descr. says geogr.
<QgsPointXY: POINT(72556.6461687610426452 23649.03288801480084658)>    

>>> canvas.extent()
<QgsRectangle: -291266.34664713160600513 405096.56972606142517179, 436379.63898465369129553 642201.49604996817652136>  

>>> //r=QgsRectangle(-290000,405000,430000,640000)
>>> //canvas.setExtent(QgsRectangle(-290000,405000,430000,640000))
// however, the spatial bookmark takes care of extents and center  

// use resize() instead to restore the original window size 
>>> canvas.resize(QSize(1205,394))  

// (there' prob.a magnif./zoom to be saved and restore as well...

Answered by quagmire on September 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP