https://issues.qgis.org/https://issues.qgis.org/favicon.ico2018-06-29T07:57:03ZQGIS Issue TrackingQGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=905942018-06-29T07:57:03ZLuigi Pirelliluipir@gmail.com
<ul></ul><p>nyall feel free to assign to me, I assigned to you just to ping you and if you can drive me faster where is the problem</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=905982018-06-29T09:55:26ZRudi von Staden
<ul><li><strong>File</strong> <a href="/attachments/download/12897/raster_calculator.PNG">raster_calculator.PNG</a> added</li></ul><p>I just ran into this issue myself. I can confirm that the fix suggested works for simple models where it's a direct input to the raster calculator. It doesn't work when the input to the raster calculator is the output from another algorithm (in that case the expression resolves to "@1").</p>
<p>In the attached screenshot, the 'Output' file is generated correctly, but lyr.parameterName() is empty for the "'Output' from algorithm 'Raster calculator'" layer.</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=906002018-06-29T10:39:07ZLuigi Pirelliluipir@gmail.com
<ul></ul><p>tnx @rudi for the test and confirmation</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=906022018-06-29T12:56:45ZRudi von Staden
<ul><li><strong>File</strong> <a href="/attachments/download/12900/rastercalculator_test.zip">rastercalculator_test.zip</a> added</li></ul><p>I've done a bit more testing, and it seems it worked because the layer name in the layer index of the project and the parameter name were coincidentally the same. If they are different, it won't work.</p>
<p>I have also found that using "OUTPUT@1" works if you add the input layer as a 'Reference layer', but if you are using two 'output' layers as input, then I'm not sure how to resolve it.</p>
<p>I've attached a test project if anyone wants some input data to test. I included a sample model which demonstrates some of the problems.</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=906082018-06-29T14:12:34ZLuigi Pirelliluipir@gmail.com
<ul></ul><p>really useful to replicate different kind of problems, really tnx</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=906092018-06-29T20:56:56ZRudi von Staden
<ul></ul><p>Glad to help, @luigi. There's a related issue at <br /><a class="external" href="https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/qgis/RasterCalculator.py#L125">https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/qgis/RasterCalculator.py#L125</a></p>
<p><code>layersDict = {os.path.basename(lyr.source().split(".")[0]): lyr for lyr in layers</code></p>
<p>The layer indexing is based on the file name. Most algorithms use <code>OUTPUT</code> as the file name, which means you won't be able to reference more than one of them in the raster calculator. I have a way to resolve that, but I don't think it's a perfect solution because it would be hard to predict in the Expression builder:</p>
<pre><code>layersDict = {}<br /> def _lyrIndex(lyrName):<br /> lyrIndex = lyrName<br /> lyrNumber = 0<br /> while lyrIndex in layersDict:<br /> lyrNumber +=1<br /> lyrIndex = f"{lyrName}{lyrNumber}" <br /> return lyrIndex<br /> if layers:<br /> for lyr in layers:<br /> name = _lyrIndex(os.path.basename(lyr.source().split(".")[0]))<br /> layersDict[name] = lyr</code></pre>
<p>I'm not sure if this should be reported as a separate issue? I also have some broader thoughts on how to improve the Raster calculator for use in models, which I've sent to the qgis-developer list (also not sure where's the best place for such discussions).</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=908012018-07-10T17:09:14ZLuigi Pirelliluipir@gmail.com
<ul><li><strong>Assignee</strong> changed from <i>Nyall Dawson</i> to <i>pablotcarreira -</i></li><li><strong>Pull Request or Patch supplied</strong> changed from <i>No</i> to <i>Yes</i></li></ul><p>a preliminary PR <a class="external" href="https://github.com/qgis/QGIS/pull/7396">https://github.com/qgis/QGIS/pull/7396</a></p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=925432018-09-04T16:12:32ZLuigi Pirelliluipir@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>Applied in changeset <a class="changeset" href="https://issues.qgis.org/projects/qgis/repository/revisions/580ecafa3265d508d8f44efb08c3d04f43e0510d" title="Merge pull request #7396 from luipir/rastercalculator_model_fix [processing] Rebirth RasterCalcu...">qgis|580ecafa3265d508d8f44efb08c3d04f43e0510d</a>.</p> QGIS Application - Bug report #19302: [processing] Modeler and Raster Calculator fail to calchttps://issues.qgis.org/issues/19302?journal_id=925452018-09-04T18:07:15ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Resolution</strong> set to <i>fixed/implemented</i></li></ul>