https://issues.qgis.org/https://issues.qgis.org/favicon.ico2015-06-03T11:43:35ZQGIS Issue TrackingQGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=617662015-06-03T11:43:35ZJürgen Fischerjef@norbit.de
<ul><li><strong>Category</strong> set to <i>Symbology</i></li></ul> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=624342015-06-17T18:03:45ZMartin Dobiaswonder.sk@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Works fine for me with tests like "$id > 10".</p>
<p>Probably something specific to your custom function... could you please post the function source and the data you used for testing?</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=625472015-06-20T06:10:36ZHarrissou Santanna
<ul></ul><p>Sorry, it's not that kind of functions. I wrote a custom function in the function editor. I was learning how this feature works so I wrote this function that retrieves for each feature the number of filled fields (NULL values are set to be shown NULL). Here it is. This code adapted to the console returns right nb for each feature.<br /><pre>@qgsfunction(args=0, group='Custom')
def compta(value1, feature, parent):
nb = 0
for idx in range(len(feature.attributes())):
attr = feature.attributes()[idx]
if not attr == NULL :
nb = nb +1
return nb</pre><br />It can be applied on any data sample.<br />Then, Style menu > Categorized, fill the field box with <b>$compta</b>. Classify.<br />The classification shows the right classes. But when applied, it doesn't apply right colors although the "count features" is right as shown in previous attached file.<br />Labelling with this function doesn't seem to work properly.</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=665342015-12-20T09:15:04ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Target version</strong> deleted (<del><i>Future Release - High Priority</i></del>)</li><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Open</i></li><li><strong>Priority</strong> changed from <i>High</i> to <i>Normal</i></li></ul> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=681772016-02-14T10:08:59ZSebastian Dietrich
<ul><li><strong>Affected QGIS version</strong> changed from <i>2.8.2</i> to <i>master</i></li></ul><p>Confirmed on master (<a class="changeset" href="https://issues.qgis.org/projects/qgis/repository/revisions/25c289441ef2074826cf27aac6fb49667e8d9a23" title="Merge pull request #2789 from SebDieBln/DbManager_FixMoveToSchema [DbManager] Fix the 'MoveToSch...">25c289441ef2074826cf27aac6fb49667e8d9a23</a>).</p>
<p>The behaviour is <strong>provider-specific</strong>. It does not occur when using a memory layer.</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=681782016-02-14T10:38:16ZSebastian Dietrich
<ul></ul><p>Seems like a caching issue. When classifying, the actual values of all attributes are fetched and the classification works correctly. However, the <em>feature</em> given to the user defined function <em>compta()</em> does not have the values filled in, so all features are counted as having no attributes set at all.</p>
<p>Probably an optimization to not fetch lots of stuff not needed for rendering anyway.</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=681822016-02-14T11:37:33ZHarrissou Santanna
<ul></ul><p>Thanks Sebastian for digging this.<br />Could this be related to <a class="issue tracker-1 status-5 priority-10 priority- closed" href="https://issues.qgis.org/issues/14273" title="Categorized style : deselecting the NULL category makes all features invisible (Closed)">#14273</a></p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=682192016-02-15T12:54:30ZSebastian Dietrich
<ul></ul><p>Another interesting observation:</p>
<p>If you pass an attribute as a parameter, that attribute's value is available within <em>feature</em>.</p>
<pre>
@qgsfunction(args='auto', group='Custom')
def firstAttr(dummy, feature, parent):
return feature.attributes()[0]
</pre>
<p>Make the expression <code>firstAttr(123)</code> and it always returns NULL when drawing a feature.<br />Make the expression <code>firstAttr("NameOfFirstAttribute")</code> and it returns the correct value when drawing a feature.</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=682282016-02-15T19:59:44ZNyall Dawson
<ul></ul><p>Sebastian - does it help if you alter <br /><a class="external" href="https://github.com/qgis/QGIS/blob/e9ef51341c2cef016648be6c619a4d43ffe362ca/python/core/__init__.py#L43">https://github.com/qgis/QGIS/blob/e9ef51341c2cef016648be6c619a4d43ffe362ca/python/core/__init__.py#L43</a></p>
<p>from <br />QgsExpression.Function.__init__(self, name, args, group, helptext, usesgeometry)</p>
<p>to <br />QgsExpression.Function.__init__(self, name, args, group, helptext, usesgeometry, [QgsFeatureRequest.AllAttributes])</p>
<p>?</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=682792016-02-16T12:10:36ZSebastian Dietrich
<ul></ul>@Nyall
<blockquote>
<p>does it help ...</p>
</blockquote>
<p>Yes! The features are rendered correctly after that change.</p>
<p>I wonder if it could be an additional parameter to the <code>@qgsfunction()</code> what attributes the function expects to be filled. E.g.<br /><pre>
@qgsfunction(args='auto', group='Custom', attrs=['attr1', 'attr2'])
</pre><br />would load the values of the attributes named <code>attr1</code> and <code>attr2</code>.<br /><pre>
@qgsfunction(args='auto', group='Custom', attrs=True)
</pre><br />would load the values of <strong>all attributes</strong>.</p>
<p>Unconditionally loading all attribute values when a user defined function is used in an expression might be a regression for some people with large layers, many attributes and a function that does not use the attribute values at all.</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=682882016-02-16T13:28:25ZNyall Dawson
<ul></ul><p>Sounds reasonable. I'd open a PR and get Nathan to take a look, this is his baby ;)</p> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=781402017-04-30T23:07:21ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Easy fix?</strong> set to <i>No</i></li><li><strong>Regression?</strong> set to <i>No</i></li></ul> QGIS Application - Bug report #12749: when using custom functions to style a layer, map canvas gives wrong colors (incoherent with legend)https://issues.qgis.org/issues/12749?journal_id=1024802019-03-09T15:09:39ZGiovanni Manghigiovanni.manghi@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>Resolution</strong> set to <i>end of life</i></li></ul><p><strong>End of life notice: QGIS 2.18 LTR</strong></p>
<p><strong>Source:</strong><br /><a class="external" href="http://blog.qgis.org/2019/03/09/end-of-life-notice-qgis-2-18-ltr/">http://blog.qgis.org/2019/03/09/end-of-life-notice-qgis-2-18-ltr/</a></p>