[Qgis-user] Local variables in field calculator

Matthias Kuhn matthias at opengis.ch
Mon May 16 14:15:26 PDT 2016



On 05/16/2016 11:08 PM, Nyall Dawson wrote:
> On 17 May 2016 at 00:02, Nelson A. de Oliveira <naoliv at gmail.com> wrote:
>> Is it possible to use local variables in the field calculator?
>>
>> For example, suppose I need to calculate the same maximum value with
>> "max(a lot of parameters)" in multiple places.
>> To avoid the same repeated expression (and also to avoid a possible
>> mistake in one of them), is there a way to create a local variable
>> with this result and then use it anywhere else in the same field
>> calculator code?
> No - that's not possible yet.
>
> Nyall

There is a workaround hack available that /may/ make sense in some
situations.

You can define it as a layer variable:

    my_max_exp = max ( a lot of parameters )

And in the expression itself reference it as

   eval( @my_max_exp )

Matthias

>
>> Thank you!
>>
>> Best regards,
>> Nelson
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

-- 
Matthias Kuhn
OPENGIS.ch - https://www.opengis.ch
Spatial • (Q)GIS • PostGIS • Open Source




More information about the Qgis-user mailing list