[Qgis-developer] Re: [saga-gis-developer] QGIS plugin

Martin Dobias wonder.sk at gmail.com
Mon Jan 3 14:35:24 EST 2011

Hi Maaza

On Mon, Jan 3, 2011 at 12:32 AM, maaza mekuria <sailmcm at yahoo.com> wrote:
> I am wondering which APIdocumentation is applicable for Python functions for Version 1.6 Copiapo release.
> For example, I was using QGSGeometry and according to the documentation it takes a point and returns a double and another argument that receives a vertex (closest) on the line segment geometry.
> Similar discrepancy exists for closestsegmentWithContext.  exists. The documentations says it like this,
> double QgsGeometry::closestegmentWithContext(qgsPoint, minDistPoint,beforeVertex)

There are small differences between C++ and Python API because of the
differences between the languages. C++ can return only one value -
when more values should be returned, it's possible to use pointers or
references to variables that will receive the output. This is also the
case of closestSegmentWithContext function. It takes a point as an
input argument, the two other variables are used only for output. In
Python one would return a tuple with several values. When wrapping C++
methods to Python, we mark which arguments are output parameters -
these are then not accepted as parameters, instead they are returned
in a tuple. An example:

>>> g = QgsGeometry.fromPolyline( [ QgsPoint(1,1), QgsPoint(2,2) ] )
>>> g.closestSegmentWithContext( QgsPoint(2,1) )
(0.5, (1.5,1.5), 1)

Here you can see that the return value (distance) is the first element
in the tuple, the other two output parameters follow.

> but in the 1.6 version I am using, it give an array of results and it must be retrieved as part of an array.
> Where would be the API docs that corresponds to a particular version of the software. I am assuming that the Python functions parallel those of C++. Until I could run with all the C++ crowd, (I am seriously contemplating to do just that, except I do not know how?) can you help me walk along the pathway of QGIS? If I could compile QGIS in QT I would jump to it immediately. I also wanted to just compile a dll in QGIS instead of compiling a complete3 application, I do not want to create a separate GUI, but just a dll that would be called like a Python

There is currently no reference guide that lists the differences
between C++ and Python API - but there are not many of them. A rule of
thumb is to consult C++ documentation (http://doc.qgis.org/) - if
there is a difference, you will get an error message that you have
passed wrong arguments. If you are not able to solve the problem by
yourself, do not hesitate to write to qgis-dev list.


More information about the Qgis-developer mailing list