[GIS] How to determine bounding box of current qgis ‘map canvas extent’ from the python console

extentspythonqgisviewer

I've asked a similar question here: How to quickly calculate bounding box coordinates of a selected polygon with qgis

…regarding a quick way to determine the bounding box of a given layer.

Is there any way to do the same thing for the current qgis view? I imagine it is an iface property but cannot find it in the documentation. Thanks.

update:
I'm working with the qgis print (map) creator right now, and I've found a button which appears to call a function that I'm alluding to. If you open the print creator, in the right side bar there is a menu button called "Item Properties". Click on this and below there is a submenu called "Extents". Expand that and there is a button called "Set to map canvas extent". This button appears to utilize the function I'm alluding to by extracting the bbox coords of the main qgis map view.

Best Answer

This will return you the extent of the canvas.

extent = iface.mapCanvas().extent()

Reference: http://qgis.org/api/classQgsMapCanvas.html#a878f0c387c9475d59c6aac425db01020

Related Question