1

I've wondered for some time how to use Cython in QGIS. I know I can integrate a Cython code in python, but I want Cython to handle QGIS classes. QGIS is built upon QT, every qgis object is a qobject written in c++, and PyQgis are python bindings to them. Is it possible to use those QGIS Object from Cython? Would it be better to import the Python binding (doesn't seem optimal) or the c++ object to Cython? Is it even doable?

I ask this because sometimes to gain performance, I'd like to rewrite some functions in Cython. My plugin is fully written in Python. My skills on cython are lacking too, maybe I'm asking something obvious. I did reread the doc multiple times. It was a big success for me to compile my first and get my first .so file to print hello world.

My english programming skills are lacking.


It seems that I'm approaching the problem in the wrong way.

I have already developed a plugin in PyQGIS. I know how to develop in Python but I don't know how stuff really works behind, because I just learned it from some python beginner courses in the net and PyQGIS cookbook.

The problem is I had to load every object in my layer a Python list because it made everything faster.
Then when I wanted to do things with my objects and made some loops in different functions. I suspect that if a loop was made in cython instead of python it would be a lot faster, as inside the loop i'm not doing any heavy time consuming task.

  • 4
    mmm I suspect you are trying to do premature optimization here. Why do you want to use Cython vs just normal Python. Remember that code you are calling via Python in Qt is C++ code and native, not Python. You only have the overhead of the Python wrapper to the APIs and Python itself which is super tiny for most things. – Nathan W Aug 21 '15 at 1:32
  • 3
    Developing plugins in C for QGIS is strongly discouraged; you in effect make your own personal trunk and miss out on new developments by the QGIS community (or a bucket load of editing for every new release). Nathan is 100% correct, start with python (pyQGIS) to get an understanding of the API and then delve into other interfaces - you are obviously new to programming in general so please don't over-complicate it or you may loose out on the enjoyment. One of the good things about python is not compiling it; plugins are compiled before running from the source if not present. – Michael Stimson Aug 21 '15 at 2:18
  • You can edit your question to add as much additional information as you feel necessary. – underdark Aug 23 '15 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.