[Qgis-developer] Some questions about PyQGIS

Martin Dobias wonder.sk at gmail.com
Sat Apr 4 18:35:38 EDT 2009


Hi German

2009/4/2 Germán Carrillo <carrillo.german at gmail.com>:
> Hi, I read the QGIS API documentation and tried to implement it. I have some
> questions/problems and I would like you to help me:
>
> 1. Is it possible to set the canvas scale manually? The only method I see is
> in MapRenderer class but it is not accessible for canvas.mapRenderer() (I
> get AttributeError: setScale).

Someone probably forgot to add this function to python bindings...
I've revised the bindings and fixed this (and few more missing
functions) in svn trunk (r10467) and it will be included in version
1.1.

But I don't think setScale() is the right method. In fact it just a
workaround for map composer to show layers with scale-based visibility
correctly. I'm not aware of direct method that would do it. You can
check QgsScaleCalculator code that calculates scale from map extent -
so you should be able to do inverse calculation.

> 2. Is it possible to set the canvas SRS manually? I only see this method on
> QgsMapLayer.

Yes, you can do it by setting destination CRS in map renderer
associated with map canvas.


> 3. I get some "class is not defined" with QgsRunProcess and QgsMapTip. How I
> should reference them? I have the qgis.core and qgis.gui imports. These are
> the 1% of the API in C++ which is not in the bindings? :P

Right :)
In case you need them, I can create those wrappers...


> 4. Implementing the QgsMapTool class I have no way to get the DoubleClick
> event, I did this:
>     -------------
>     def canvasDoubleClickEvent(self,event):
>         print "Yes"
>     -------------
>    But it doesn't work. I get two Raise events instead of DoubleClick one.
> (I really want the DoubleClick event)

I have no idea about this one. The bindings are in place, so the
problem might be in dispatch of double click from canvas.

> Thanks for the project and for the bindings.

Thanks for reporting back the problems :)

Martin


More information about the Qgis-developer mailing list