[Qgis-developer] How to pass xMax, xMin, yMax, yMin of a current zoomed view

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Oct 21 17:36:17 EDT 2009


On Wed, Oct 21, 2009 at 10:14 PM, Echavarria Gregory, Maria Angelica
<m.echavarriagregory at umiami.edu> wrote:
> HI EVERYBODY,
>
> Im creating a Qgis application.

 In Python or C++? An application or a plugin? What version of Qgis?
It's probably worth moving to the latest 1.x series since that's where
all the developer work is (and there's lots of bugfixes and new
features).

> I need to pass to my code the map coordinates of my current zoomed-in view (need the actual corners in GWS to set the bounds of an image that will be further created in my code and then will be superimposed to this exact map area). I found QgsRect.xMax(), xMin(), yMax() and yMin()... and QgsRect.extent(). Is QgsRect the correct class? how should I use these functions if correct for my purpose? should I write them inside my zoomIn tool method after self.canvas.setMapTool(self.toolZoomIn)? none of my trials has worked... please I need guidance.

 I think QgsRect is now QgsRectangle in the latest Qgis - the API doc
will tell you what things are for:

http://doc.qgis.org/stable/classQgsRectangle.html

 All the "min" and "max" words are spelt out in full now too -
'xMinimum' and so forth.

 Although these are derived from C++, they translate easily to Python.
For QgsRectangle it says it is typically used for layer extents or
view extents, so right up your use case.

 If you're writing a map tool then you need to figure out how signals
work to trigger bits of your code when the user interacts - check out
some of the simple plugins that interact with the map to see how.

 Your map tool code will have to get the extent of the canvas from the
'iface' object that it gets when it first loads. If you do:

 ext = iface.mapCanvas().extent()

 then you get a QgsRectangle object that you can pass around. I'm not
sure at the moment if this is in projected coordinates though... You
may need to apply a transform... There's still a lot to do!

 You should sit down with some existing plugin code and really
understand how it hooks into Qgis!

Barry


More information about the Qgis-developer mailing list