[Qgis-developer] Map Canvas Current Zoomed Extent

Martin Dobias wonder.sk at gmail.com
Mon Jan 13 02:01:19 PST 2014


Hi Bjorn

On Mon, Jan 13, 2014 at 4:28 PM, Bjorn Nyberg
<bjorn.burr.nyberg at gmail.com> wrote:
> Hi,
>
> I had a couple of questions that I was hoping could be answered here on the
> mailing list. I am trying to write some code to find the current zoomed in
> rectangular extent of my Map Canvas by the following pyqgis API function
>  QgsMapCanvas.extent()
>
> however I receive the error
>
> TypeError: QgsMapCanvas.extent(): first argument of unbound method must have
> type 'QgsMapCanvas'
>
> Im not entirely certain what that is saying - first argument of unbound
> method?

I suspect that you are literally trying to call
"QgsMapCanvas.extent()" from Python, which is not possible. You need
to use an instance of QgsMapCanvas to call this (or any other) method.
The call you are doing would be possible only if the extent() method
would be a static method of the QgsMapCanvas class. Try this in QGIS
python console:
>>> mc = iface.mapCanvas()
>>> mc.extent()

Martin


More information about the Qgis-developer mailing list