<div dir="ltr"><div><div><div><div><font><span style="font-family:arial,helvetica,sans-serif">I developed a plugin called <a href="http://geogear.wordpress.com/2014/11/13/reffunctions-v1-0/"><span style="font-style:italic;text-decoration:underline;color:rgb(0,0,255)">refFunctions v1.0</span></a></span></font><font><span style="font-family:arial,helvetica,sans-serif"> that extends expressions with a new group of functions.<br>In Expression calculator, under the group 'Reference' you will find </span></font><font><span style="font-family:arial,helvetica,sans-serif">a function called <span>dbquery(targetLayer,targetField,whereClause)<br></span></span></font></div></div></div><font><span style="font-family:arial,helvetica,sans-serif"><span>It was developed keeping in mind the reference to other layers, but I think you can use it with the same layer. </span><span><br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span>You can pass the field containing conditional expression in whereClause parameter and retrieve the same field used in where clause. <br>I you get NULL the test is false otherwise is true.<br><br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span>for example (with field "condition" containing 'testField = 1'):<br><br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span>CASE<br>WHEN dbquery('samelayer','testFiled',"condition") = NULL THEN 0<br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span>ELSE 1<br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span>END<br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span><br></span></span></font></div><div><font><span style="font-family:arial,helvetica,sans-serif"><span>Pay attention to quotes!</span></span></font><span style="font-family:"MS Shell Dlg 2";font-size:8pt;font-weight:600"><br></span></div><div><span style="font-family:"MS Shell Dlg 2";font-size:8pt;font-weight:600"><br><br></span></div><font><span style="font-family:"MS Shell Dlg 2"">Here is the description:</span></font><span style="font-family:"MS Shell Dlg 2";font-size:8pt;font-weight:600"><br></span><br><span style="font-family:"luxi serif,georgia,times new roman,times,serif";font-size:large;font-weight:600;color:rgb(114,159,207);background-color:rgb(246,246,246)">dbquery function</span>
<p style="margin:0px;text-indent:0px"><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"><br>Retrieve first targetField value from targetLayer when whereClause is true </span></p>
<p style="margin:12px 0px;text-indent:0px;background-color:rgb(246,246,246)"><span style="font-family:"luxi serif,georgia,times new roman,times,serif";font-size:medium;font-weight:600;color:rgb(114,159,207);background-color:rgb(246,246,246)">Syntax</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"> </span></p>
<p style="margin:12px 0px;text-indent:0px"><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)">dbquery(</span><span style="font-family:"arial,sans-serif";font-style:italic;color:rgb(0,0,0)">targetLayer,targetField,whereClause</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)">) </span></p>
<p style="margin:12px 0px;text-indent:0px;background-color:rgb(246,246,246)"><span style="font-family:"luxi serif,georgia,times new roman,times,serif";font-size:medium;font-weight:600;color:rgb(114,159,207);background-color:rgb(246,246,246)">Arguments</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"> </span></p>
<p style="margin:12px 0px;text-indent:0px"><span style="font-family:"arial,sans-serif";font-style:italic;color:rgb(0,0,0)">targetLayer</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"> → the name of a currently loaded layer, for example 'myLayer'.<br></span><span style="font-family:"arial,sans-serif";font-style:italic;color:rgb(0,0,0)">targetLayer</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"> → 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 <br></span><span style="font-family:"arial,sans-serif";font-style:italic;color:rgb(0,0,0)">whereClause</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"> → a valid expression string without duoble quotes to identify fields, for example 'field1 > 1 and field2 = "foo"' <br></span></p>
<p style="margin:12px 0px;text-indent:0px;background-color:rgb(246,246,246)"><span style="font-family:"luxi serif,georgia,times new roman,times,serif";font-size:medium;font-weight:600;color:rgb(114,159,207);background-color:rgb(246,246,246)">Example</span><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)"> </span></p>
<p style="margin:12px 0px;text-indent:0px"><span style="font-family:"arial,sans-serif";color:rgb(0,0,0)">dbquery('myLayer','myField','field1 > 1 and field2 = "foo"') <br>dbquery('myLayer','$geometry','field1 > 1 and field2 = "foo"') <br></span></p><div><div><div><p style="margin:0px;text-indent:0px"><br><span style="font-family:"MS Shell Dlg 2";font-size:8pt"></span></p><p style="margin:0px;text-indent:0px"><span style="font-family:"MS Shell Dlg 2";font-size:8pt"><br></span></p><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-02-26 14:00 GMT+01:00 Alexandre Neto <span dir="ltr"><<a href="mailto:senhor.neto@gmail.com" target="_blank">senhor.neto@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello all,<div><br></div><div>Does any one know how if it's possible to evaluate an all string as an expression in expression builder.</div><div><br></div><div>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:</div><div><br></div><div>'"field_1" = 20'</div><div><br></div><div>Is there a way to evaluate this as an conditional expression?<br></div><div><br></div><div>Thanks,</div><div><br></div><div>Alexandre Neto</div></div>
<br>_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br></blockquote></div><br></div>