[QGIS-Developer] [PyQGIS] Unexpected crash using: QgsFeatureRenderer.symbolForFeature()

Benjamin Jakimow benjamin.jakimow at geo.hu-berlin.de
Thu Mar 4 03:17:17 PST 2021


Hi Janvier,

maybee you need to use it within a startRender and stopRender section:

renderContext = QgsRenderContext()
renderContext.setExtent(layer.extent())
renderer = layer.renderer().clone()
renderer.startRender(renderContext, layer.fields())
features = layer.getFeatures(fids)
for i, featurein enumerate(features):
     symbol = renderer.symbolForFeature(feature, renderContext)
     # ... renderer.stopRender(renderContext)

Greetings, Benjamin

Am 04/03/2021 um 11:46 schrieb Janvier Thomas:
>
> Hi,
>
>
> I got an issue with SIP python bindings…
> I’m looking to loop over QgsVectorLayer features to convert geometries 
> to mesh primitives (cells) …
>
> I had a first problem with the non-const (unexpected crash about SIP 
> methods)
> |for part in feature.geometry().parts():|
> that I solved using the const one
> |for p in f.geometry().constParts():|
>
> ||
>
> But now I’m facing a similar crash when trying to identify the 
> symbol/category/legendKey of each feature
> (the aim is to add the legendKey as a cell attribute to link color/LUT 
> between the mesh and vectorlayer)
>
> I do it this way:
> layer.renderer().symbolForFeature(feature, context)
>
> But ends up with a :
>
> Crash ID: cb1c4f2b11cbd392a38c522a5ed1e194e060e4a0
>
> Stack Trace
>
> QgsExpression::evaluate :
>
> QgsCategorizedSymbolRenderer::valueForFeature :
>
> QgsCategorizedSymbolRenderer::originalSymbolForFeature :
>
> PyInit__core :
>
> PyMethodDef_RawFastCallKeywords :
>
> PyMethodDef_RawFastCallKeywords :
>
> PyEval_EvalFrameDefault :
>
> PyEval_EvalCodeWithName :
>
> I opened an Issue here (not sure this is relevant):
> Unexpected crash using: QgsFeatureRenderer.symbolForFeature() · Issue 
> #68 · qgis/pyqgis (github.com) <https://github.com/qgis/pyqgis/issues/68>
>
> Thanks a lot
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
Benjamin Jakimow, Doctoral Researcher
Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin

e-mail: benjamin.jakimow at geo.hu-berlin.de

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:    https://hu-berlin.de/eo-lab

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210304/1691cbf8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5422 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210304/1691cbf8/attachment.bin>


More information about the QGIS-Developer mailing list