[QGIS-Developer] Purpose and function of "referenced_columns" in Python expression functions?

Matthias Kuhn matthias at opengis.ch
Mon Nov 22 05:48:44 PST 2021


Hi Hannes,

This information can be used by the expression engine to determine what
needs to be requested from the provider.
This can lead to significant performance improvements, depending on the
scenario.

Depending on other functions used in the expression and the capabilities of
the provider itself, the request may or may not include them.

As stated in the help, it's what the function *requires*, these attributes
are guaranteed to be available. Others may still be there.

Cheers
Matthias


On Mon, Nov 22, 2021 at 2:41 PM Johannes Kröger (WhereGroup) <
johannes.kroeger at wheregroup.com> wrote:

> Hi list,
>
>
> https://docs.qgis.org/3.22/en/docs/user_manual/expressions/expression.html#function-editor
> mentions the optional keyword argument "referenced_columns" to the
> `@qgsfunction` decorator. It says
>
>  > referenced_columns=[list]: An array of attribute names that are
> required to the function. Defaults to
>  > [QgsFeatureRequest.ALL_ATTRIBUTES].
>
> That, and examples where it is used in other people's code, led me to
> believe that the feature's attributes would not be accessible unless
> listed in that parameter or if the parameter was omitted (-> default
> value getting used -> default is all attributes).
>
> The default code that gets inserted into the editor includes the
> decorator `@qgsfunction(args='auto', group='Custom',
> referenced_columns=[])` so I'd assume that I would not be able to use
> any attributes in the function.
>
> In reality I can access them just fine though, e. g. `feature["name"]`
> if I had features with a "name" attribute and that default
> `referenced_columns=[]`.
>
> I can even do so if I used `referenced_columns=["foo", "bar"]`!
> `feature["name"]` is still perfectly accessible.
>
> Is this a bug or by design? If by design, what purpose does this
> parameter have?
>
> Thanks
> Hannes
>
> --
> Johannes Kröger / GIS-Entwickler/-Berater
> WhereGroup GmbH
> Eifelstraße 7
> 53119 Bonn
> Germany
>
> Tel: +49 (0)228 / 90 90 38 - 36
> Fax: +49 (0)228 / 90 90 38 - 11
>
> johannes.kroeger at wheregroup.com
> www.wheregroup.com
> Geschäftsführer:
> Olaf Knopp, Peter Stamm
> Amtsgericht Bonn, HRB 9885
> -------------------------------
>
> ********************************************
> Where2B Konferenz 2021
> 16. Dezember 2021
> im Universitätsclub Bonn und online
> https://where2b-conference.com/
> ********************************************
>
> _______________________________________________
> 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/20211122/3337707a/attachment.html>


More information about the QGIS-Developer mailing list