<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Oh "for Pete's sake". - I'd love someone to explain why that is
needed and not auto-turned on or defaulted to True.<br>
<br>
Thank you for bringing my attention to that tidbit.<br>
<br>
Kind regards,<br>
Zoltan<br>
<br>
<br>
<div class="moz-cite-prefix">On 2021-10-19 19:07, DelazJ wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAECJsSppt_6AxxFB4C24yPB4hj3hDe3w1SZo-YiGqNkSe=j1rQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Hi Zoltan,</div>
<div><br>
</div>
<div>You are playing with geometry so you need usesgeometry=True
in your function decorator.</div>
<div>See <a
href="https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/expression.html#function-editor"
moz-do-not-send="true" class="moz-txt-link-freetext">https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/expression.html#function-editor</a>
or the help section in the Function Editor tab.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Harrissou<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Le mar. 19 oct. 2021 à 18:33,
Zoltan <<a href="mailto:zoltans@geograph.co.za"
moz-do-not-send="true" class="moz-txt-link-freetext">zoltans@geograph.co.za</a>>
a écrit :<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div> Hi,<br>
Me again :-(<br>
<br>
I've written a custom function in Field Calculator and want
to put its return value into a new Text field in the
attribute table.<br>
<br>
When I step through the features I get the correct and
expected values shown next to 'Preview'<br>
But <br>
when I click OK to run the Field Calculator, it runs for a
long enough time, auto-closes on completion and in the
attribute table the new field is created, but value is
'Nothing for None' for all features.<br>
<b>Note:</b> variable rd_at reflects correct contents when
stepping through and observing 'Preview' but seems to revert
to Nonetype when running the function.<br>
<br>
What am I missing regarding using custom functions?<br>
Is it an intended thing that the Field Calculator
auto-closes after running a custom function?<br>
<br>
Thanks again,<br>
Kind regards,<br>
Zoltan<br>
<br>
<b>Note:</b> The msg variable was introduced in case
placing 'return' in various lines in the script was causing
problems. I have also made the script below "more pedantic"
to try and debug it.<br>
<blockquote>from qgis.core import *<br>
from qgis.gui import *<br>
import processing<br>
<br>
@qgsfunction(args='auto', group='Custom',
referenced_columns=[])<br>
def del_cutboxes(feature, parent):<br>
geom = feature.geometry()<br>
attr = feature.attributes()<br>
rd_at = str(attr[5])<br>
lyr_rcl =
QgsVectorLayer('Z:/Projects/RCL_boxes.shp','lyrrcl','ogr')<br>
rcl_feats = lyr_rcl.getFeatures()<br>
msg = ''<br>
for rcl_feat in rcl_feats:<br>
if len(msg) == 0:<br>
rclbox = rcl_feat.geometry()<br>
if rclbox.contains(geom):<br>
if rcl_feat.attributes()[0] is not rd_at:<br>
#feature.delete()<br>
msg = 'ToDelete ' + rd_at<br>
else:<br>
msg = 'ToKeep ' + rd_at<br>
if len(msg) == 0:<br>
msg = 'Nothing for ' + rd_at<br>
return msg<br>
</blockquote>
<br>
<br>
<br>
<br>
<br>
<pre cols="72">--
=============================================
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services
Cape Town, South Africa.
Mobile: +27-83-6004028 (Signal, not WhatsApp)
<a href="http://www.geograph.co.za" target="_blank" moz-do-not-send="true">www.geograph.co.za</a>
=============================================
</pre>
</div>
_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">Qgis-user@lists.osgeo.org</a><br>
List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-user"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-user"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
</blockquote>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
=============================================
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services
Cape Town, South Africa.
Mobile: +27-83-6004028 (Signal, not WhatsApp)
<a class="moz-txt-link-abbreviated" href="http://www.geograph.co.za">www.geograph.co.za</a>
=============================================
</pre>
</body>
</html>