[QGIS-Developer] Remove layer variable
Simon Gröchenig
gis at sgroe.at
Wed Jun 11 07:48:17 PDT 2025
Thank you, Nyall. That works.
Simon
Am 05.06.2025 01:23, schrieb Nyall Dawson:
> On Mon, 2 Jun 2025 at 19:16, Simon Gröchenig via QGIS-Developer
> <qgis-developer at lists.osgeo.org> wrote:
>
>> Hi,
>>
>> how can I remove a layer variable with Python?
>>
>> The following returns true, but does not work.
>>
>> QgsExpressionContextUtils.layerScope(layer).removeVariable("variable_name")
>
> That's cos it's just removing the variable from a copy of the layer's
> expression context scope, not from the layer itself.
>
> It's rather gross, but try
> https://qgis.org/pyqgis/3.40/core/QgsExpressionContextUtils.html#qgis.core.QgsExpressionContextUtils.setLayerVariables
> -- you'll need to first retrieve the existing variables via
> https://qgis.org/pyqgis/3.40/core/QgsExpressionContextUtils.html#qgis.core.QgsExpressionContextUtils.layerScope
> and then build a dictionary of the variables you want to keep by
> iterating over
> https://qgis.org/pyqgis/3.40/core/QgsExpressionContextScope.html#qgis.core.QgsExpressionContextScope.variableNames
>
> Hope that helps!
> Nyall
>
>> Best regards
>> Simon
>>
>> _____________________
>> Simon Gröchenig
>> GIS Support und Training
>> Treffling 73 - 9871 Seeboden - Österreich
>> Tel.: +43 699 11 22 31 22
>> Web: https://www.sgroe.at
>> E-Mail: gis at sgroe.at
>> _______________________________________________
>> 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
--
_____________________
Simon Gröchenig
GIS Support und Training
Treffling 73 - 9871 Seeboden - Österreich
Tel.: +43 699 11 22 31 22
Web: https://www.sgroe.at
E-Mail: gis at sgroe.at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250611/5314608e/attachment.htm>
More information about the QGIS-Developer
mailing list