[Qgis-user] How evaluate a string as an expression in expression builder

Enrico Ferreguti enricofer at gmail.com
Thu Feb 26 06:52:08 PST 2015


I developed a plugin called refFunctions v1.0
<http://geogear.wordpress.com/2014/11/13/reffunctions-v1-0/> that extends
expressions with a new group of functions.
In Expression calculator, under the group 'Reference' you will find a
function called dbquery(targetLayer,targetField,whereClause)
It was developed keeping in mind the reference to other layers, but I think
you can use it with the same layer.
You can pass the field containing conditional expression in whereClause
parameter and retrieve the same field used in where clause.
I you get NULL the test is false otherwise is true.

for example (with field "condition" containing 'testField = 1'):

CASE
WHEN dbquery('samelayer','testFiled',"condition") = NULL THEN 0
ELSE 1
END

Pay attention to quotes!


Here is the description:

dbquery function


Retrieve first targetField value from targetLayer when whereClause is true

Syntax

dbquery(targetLayer,targetField,whereClause)

Arguments

targetLayer → the name of a currently loaded layer, for example 'myLayer'.
targetLayer → a field of targetLayer whom value is needed, for example
'myField'. In case of multiple results only the first is retrieved. If
targetLayer = '$geometry' geometry value is retrieved
whereClause → a valid expression string without duoble quotes to identify
fields, for example 'field1 > 1 and field2 = "foo"'

Example

dbquery('myLayer','myField','field1 > 1 and field2 = "foo"')
dbquery('myLayer','$geometry','field1 > 1 and field2 = "foo"')





2015-02-26 14:00 GMT+01:00 Alexandre Neto <senhor.neto at gmail.com>:

> Hello all,
>
> Does any one know how if it's possible to evaluate an all string as an
> expression in expression builder.
>
> What I'm aiming to be able to do is to dynamicly create expression based
> on other fields. So Imagine I have attribute with a string like this:
>
> '"field_1" = 20'
>
> Is there a way to evaluate this as an conditional expression?
>
> Thanks,
>
> Alexandre Neto
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150226/2a49a70e/attachment.html>


More information about the Qgis-user mailing list