[QGIS-Developer] Porting Create Grid algorithm to C++

Clemens Raffler clemens.raffler at gmail.com
Mon Sep 30 12:01:27 PDT 2019


Thank you Nyall for your feedback and for mentoring me in this process! 
I will definitely have a look at other Python algorithms.

I managed to open a pull request 
(https://github.com/qgis/QGIS/pull/32070) containing the new algorithm 
sources and the integration into cmake.
I ran into some problems when applying the prepare_commit.sh script 
(output: nothing was modified) but everything else went smoothly.

Please have a look at the code and feel free to contact me!

Best regards,
Clemens


On 30.09.19 02:08, Nyall Dawson wrote:
> On Mon, 30 Sep 2019 at 03:06, Clemens Raffler <clemens.raffler at gmail.com> wrote:
>> Dear QGIS Developers,
>>
>> lately I have been using the 'Create Grid' algorithm a lot on huge areas
>> and with a rather fine grid resolution. I was not surprised that
>> creating a very fine grid took a very long time as the algorithm is
>> currently implemented in python.
>>
>> In order to speed up my work I decided to experiment a little with C++
>> (coming from a python background) development in QGIS and ported the
>> algorithm to C++ based on other native algorithms. The code is working
>> very well, the grid creation process has been sped up significantly. I
>> would now like to contribute the code to the QGIS project so that other
>> users can benefit from the speedup.
> Sounds fantastic, and a very valuable (and desired) contribution! Nice work!
>
>> - Is there any reason why certain algorithms (eg. the Create Grid alg)
>> should not be available in C++?
> No. In fact, the opposite! The long-term goal is to port all these
> algorithms away from Python and to c++. Python is GREAT for plugin
> based algorithms and for quickly developing new algorithms, but it's
> just not competitive in speed vs the c++ algorithms. We've also had a
> LOT of issues in the past where Python algorithms break due to lack of
> compile time checks when QGIS API (or other Processing Python code) is
> revised. In contrast, I'm not aware of a single regression of this
> nature in any of the ported c++ algorithms.
>
> (My advice for readers out there: don't write big, complex
> applications in Python. full stop.)
>
>> - As I am not familiar with the processes how native processing
>> algorithms get committed to the main repository (pull requests,
>> prepare-commit.sh, sip, etc.), would anybody like to help/mentor/guide
>> me through this process and review the code?
> **raises hand**
>
>> - Are there any special requirements on testing infrastructure for C++
>> algs which should be implemented too (I have not worked with tests so far)?
> Looks like there's already good test coverage with the existing Python
> algorithm. These existing tests will carry over to the c++ port, so
> it's likely that nothing extra is required here.
>
> In general, there's some "desirable changes" which we are encouraging
> when porting an existing algorithm to c++, but none of them apply in
> this particular case. Specifically:
>
> - use the QgsProcessingFeatureBasedAlgorithm subclass wherever possible.
> - add support for dynamic parameters where desirable.
>
>
>> So far, my experience with porting python algs to C++ has been very good
>> with Create Grid and I would like to work on other ports if everything
>> goes well.
> That's great to hear!  I'd suggest having a look at a really simple
> feature based algorithm like DensifyGeometries as a great candidate
> for learning. There's almost no logic in the Python code for this one,
> so it would be a great one to learn the overall process of porting to
> c++ without the complexities of having to port a lot of
> python-specific logic.
>
> Nyall


More information about the QGIS-Developer mailing list