[QGIS-Developer] Updating qgis:rastercalculator to work better in models

Luigi Pirelli luipir at gmail.com
Tue Jul 10 10:10:56 PDT 2018


please give a try to this preliminary PR that should fix the use of raster
calculator in the modeler

https://github.com/qgis/QGIS/pull/7396

Luigi Pirelli

**************************************************************************************************
* LinkedIn: https://www.linkedin.com/in/luigipirelli
* Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli
* GitHub: https://github.com/luipir
* Mastering QGIS 2nd Edition:
*
https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition
* Hire me: http://goo.gl/BYRQKg
**************************************************************************************************


On Mon, 9 Jul 2018 at 11:02, Luigi Pirelli <luipir at gmail.com> wrote:

> Hi @Rudi von Staden <rudivs at gmail.com> , @Nyall Dawson
> <nyall.dawson at gmail.com> and @Matthias Kuhn <matthias at opengis.ch>
>
> in the meantime I had to resolve compilation problems and OS update I'll
> show you what I'm doing to resurrect rastercalculator in modeler trying to
> evaluate if I'm doing well.
>
> the principal problem (but not the only one) to run raster calculator in a
> modeler is to map input value to the formula. This is a generic problem
> that can be applied to any algorithm that need to map input in something
> internal to the algorithm.
>
> The main problems is that the algorithm context scope hadn't information
> to allow this mapping. I added:
>
> context.setExpressionContext(expContext);
> here
>
> https://github.com/qgis/QGIS/blob/master/src/core/processing/models/qgsprocessingmodelalgorithm.cpp#L276
> and naming the createExpressionContextScopeForChildAlgorithm scope
> "algorithm_inputs" (actually the added scope does not have name, because
> was not necessary)
>
> and add this mapping in ::variablesForChildAlgorithm
>
> https://github.com/qgis/QGIS/blob/master/src/core/processing/models/qgsprocessingmodelalgorithm.cpp#L431
> with value:
> <var name>: <maplayer instance>
> In this moment only <var name>_[extent] variable are added in this context
> scope
>
> the idea, in the processAlgorithm python part, is to get the expression
> context from ProcessingContext and substitude <var name> with <maplayer
> source> in the formula that will be executed by QgsRasterCalculator
>
> conceptually it works, but many other problems in context and parameter
> settings are present that seems they are more generic modeler problems I'm
> still trying to solve and reproduce them)
>
> What I'm not sure is to use the expressionContext to store this
> information instead of a different or new contextScope. the advantages is
> that the new input parameters are available in the expression editor
> because available in the context.
>
> as soon as I can I'll give you a PR where to talk about real code... in
> this moment I doing tests if my approach is (almost) correct and finding
> all limitation using these pathces in simple test models
>
> Luigi Pirelli
>
>
> **************************************************************************************************
> * LinkedIn: https://www.linkedin.com/in/luigipirelli
> * Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli
> * GitHub: https://github.com/luipir
> * Mastering QGIS 2nd Edition:
> *
> https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition
> * Hire me: http://goo.gl/BYRQKg
>
> **************************************************************************************************
>
>
> On Wed, 4 Jul 2018 at 00:24, Luigi Pirelli <luipir at gmail.com> wrote:
>
>> I was supposing is was subject to the GSOC about qgis/grass... but I can
>> be wrong.
>> Luigi Pirelli
>>
>>
>> **************************************************************************************************
>> * LinkedIn: https://www.linkedin.com/in/luigipirelli
>> * Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli
>> * GitHub: https://github.com/luipir
>> * Mastering QGIS 2nd Edition:
>> *
>> https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition
>> * Hire me: http://goo.gl/BYRQKg
>>
>> **************************************************************************************************
>>
>>
>> On Tue, 3 Jul 2018 at 18:31, Giovanni Manghi <giovanni.manghi at gmail.com>
>> wrote:
>>
>>> Hi Luigi,
>>>
>>> > I know that some power users are stuk to 2.18 for the lack r.calc in
>>> grass7
>>> > integration in qgis (that seems will be solved soon)
>>>
>>> what is greatly missing (in GRASS7) is r.mapcalculator.py, a script
>>> made on top of r.mapcalc that among the other things allowed us to
>>> have in Processing a nice way to use r.mapcalc (because it worked via
>>> normal description files while r.mpalcalc does not, and any attempt to
>>> make it work in Processing was not very succesful).
>>>
>>> Are you saying that this script is being ported in GRASS7?
>>>
>>> cheers
>>>
>>> -- G --
>>> _______________________________________________
>>> QGIS-Developer mailing list
>>> QGIS-Developer at lists.osgeo.org
>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180710/81b53054/attachment.html>


More information about the QGIS-Developer mailing list