<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<p>Hi Janvier,</p>
<p>maybee you need to use it within a startRender and stopRender
section:</p>
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Consolas',monospace;font-size:9,8pt;">renderContext = QgsRenderContext()
renderContext.setExtent(layer.extent())
renderer = layer.renderer().clone()
renderer.startRender(renderContext<span style="color:#cc7832;">, </span>layer.fields())
features = layer.getFeatures(fids)
<span style="color:#cc7832;">for </span>i<span style="color:#cc7832;">, </span>feature <span style="color:#cc7832;">in </span><span style="color:#8888c6;">enumerate</span>(features):
symbol = renderer.symbolForFeature(feature<span style="color:#cc7832;">, </span>renderContext)
<span style="color:#808080;"># ...
</span>renderer.stopRender(renderContext)
</pre>
<div class="moz-cite-prefix">Greetings, Benjamin</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Am 04/03/2021 um 11:46 schrieb Janvier
Thomas:<br>
</div>
<blockquote type="cite"
cite="mid:VI1P190MB065514D3DEC0BF3BFB1C6A88ED979@VI1P190MB0655.EURP190.PROD.OUTLOOK.COM">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}@font-face
{font-family:"Segoe UI";
panose-1:2 11 5 2 4 2 4 2 2 3;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}code
{mso-style-priority:99;
font-family:"Courier New";}pre
{mso-style-priority:99;
mso-style-link:"Pr\00E9format\00E9 HTML Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}span.PrformatHTMLCar
{mso-style-name:"Pr\00E9format\00E9 HTML Car";
mso-style-priority:99;
mso-style-link:"Pr\00E9format\00E9 HTML";
font-family:"Courier New";
mso-fareast-language:FR;}span.pl-c1
{mso-style-name:pl-c1;}.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><br>
I got an issue with SIP python bindings…<br>
I’m looking to loop over QgsVectorLayer features to convert
geometries to mesh primitives (cells) …<br>
<br>
I had a first problem with the non-const (unexpected crash
about SIP methods)<br>
</span><code><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US">for part in feature.geometry().parts():</span></code><span
style="font-size:10.5pt;font-family:"Segoe
UI",sans-serif;color:#24292E;background:white"
lang="EN-US"><br>
that I solved using the const one<br>
</span><code><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US">for p in f.geometry().constParts():<o:p></o:p></span></code></p>
<p class="MsoNormal"><code><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US"><o:p> </o:p></span></code></p>
<p class="MsoNormal"><span lang="EN-US">But now I’m facing a
similar crash when trying to identify the
symbol/category/legendKey of each feature<br>
(the aim is to add the legendKey as a cell attribute to link
color/LUT between the mesh and vectorlayer)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I do it this way:<br>
</span><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US">layer.renderer().symbolForFeature(feature,
context)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But ends up with a :<br>
<br>
</span><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">Crash ID:
cb1c4f2b11cbd392a38c522a5ed1e194e060e4a0<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">Stack Trace<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">QgsExpression::evaluate :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">QgsCategorizedSymbolRenderer::valueForFeature :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">QgsCategorizedSymbolRenderer::originalSymbolForFeature
:<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">PyInit__core :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">PyMethodDef_RawFastCallKeywords :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">PyMethodDef_RawFastCallKeywords :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">PyEval_EvalFrameDefault :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E;mso-fareast-language:FR"
lang="EN-US">PyEval_EvalCodeWithName :<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:Consolas;color:#24292E"
lang="EN-US"></span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I opened an Issue here
(not sure this is relevant):<br>
</span><a href="https://github.com/qgis/pyqgis/issues/68"
moz-do-not-send="true"><span lang="EN-US">Unexpected crash
using: QgsFeatureRenderer.symbolForFeature() · Issue #68 ·
qgis/pyqgis (github.com)</span></a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks a lot<span lang="EN-US"><o:p></o:p></span></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Benjamin Jakimow, Doctoral Researcher
Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin
e-mail: <a class="moz-txt-link-abbreviated" href="mailto:benjamin.jakimow@geo.hu-berlin.de">benjamin.jakimow@geo.hu-berlin.de</a>
phone: +49 (0) 30 2093 6846
mobile: +49 (0) 157 5656 8477
fax: +49 (0) 30 2093 6848
mail: Unter den Linden 6 | 10099 Berlin | Germany
room: 2'211
web: <a class="moz-txt-link-freetext" href="https://hu-berlin.de/eo-lab">https://hu-berlin.de/eo-lab</a></pre>
</body>
</html>