[Qgis-user] Re : How evaluate a string as an expression in expression builder
Junior
delazj at gmail.com
Thu Feb 26 08:34:39 PST 2015
Hi,
Can't this be done with the simple use of case when condition? Something like:
CASE WHEN "field_1"= 20 THEN 'something True' ELSE 'something false' END
Envoyé depuis mon HTC
----- Reply message -----
De : "Enrico Ferreguti" <enricofer at gmail.com>
Pour : "Alexandre Neto" <senhor.neto at gmail.com>
Cc : "QGIS User" <qgis-user at lists.osgeo.org>
Objet : [Qgis-user] How evaluate a string as an expression in expression builder
Date : jeu., févr. 26, 2015 15:52
I developed a plugin called 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/51326a5d/attachment.html>
More information about the Qgis-user
mailing list