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

Janvier Thomas t.janvier at brgm.fr
Thu Mar 4 06:24:12 PST 2021


Thanks a lot that did the trick !
I'll try to mention it in the doc.



Thomas JANVIER
3D Geomodelling developper
DGR/CIM

3 av. Claude-Guillemin - BP 36009 - 45060 ORLÉANS Cedex 2
Tel.: +33 (0)2 38 64 33 39/ t.janvier at brgm.fr
www.brgm.fr


BRGM - THE FRENCH GEOLOGICAL SURVEY
Newsletter BRGM Infos

         



-----Message d'origine-----
De : QGIS-Developer <qgis-developer-bounces at lists.osgeo.org> De la part de qgis-developer-request at lists.osgeo.org
Envoyé : jeudi 4 mars 2021 14:50
À : qgis-developer at lists.osgeo.org
Objet : QGIS-Developer Digest, Vol 185, Issue 18

Send QGIS-Developer mailing list submissions to
	qgis-developer at lists.osgeo.org

To subscribe or unsubscribe via the World Wide Web, visit
	https://urldefense.com/v3/__https://lists.osgeo.org/mailman/listinfo/qgis-developer__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6rPFD9Q7$
or, via email, send a message with subject or body 'help' to
	qgis-developer-request at lists.osgeo.org

You can reach the person managing the list at
	qgis-developer-owner at lists.osgeo.org

When replying, please edit your Subject line so it is more specific than "Re: Contents of QGIS-Developer digest..."


Today's Topics:

   1. Re: [PyQGIS] Unexpected crash using:
      QgsFeatureRenderer.symbolForFeature() (Richard Duivenvoorde)
   2. Re: [PyQGIS] Unexpected crash using:
      QgsFeatureRenderer.symbolForFeature() (Benjamin Jakimow)
   3. Re: PYQGIS - OpenGL in QgsPluginLayer (Martin Dobias)


----------------------------------------------------------------------

Message: 1
Date: Thu, 4 Mar 2021 11:52:41 +0100
From: Richard Duivenvoorde <rdmailings at duif.net>
To: Janvier Thomas <t.janvier at brgm.fr>,
	"qgis-developer at lists.osgeo.org" <qgis-developer at lists.osgeo.org>
Subject: Re: [QGIS-Developer] [PyQGIS] Unexpected crash using:
	QgsFeatureRenderer.symbolForFeature()
Message-ID: <990d7c38-a08c-3c21-b703-bead2a4f11b9 at duif.net>
Content-Type: text/plain; charset=windows-1252

On 3/4/21 11:46 AM, Janvier Thomas wrote:
> ?
> I opened an Issue here (not sure this is relevant):
> Unexpected crash using: QgsFeatureRenderer.symbolForFeature() ? Issue 
> #68 ? qgis/pyqgis (github.com) 
> <https://urldefense.com/v3/__https://github.com/qgis/pyqgis/issues/68_
> _;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6t
> __RiXG$ >

Hi Janvier,

FYI: that issue tracker is for the pyqgis documentation builder. 
Better just use https://urldefense.com/v3/__https://github.com/qgis/qgis/issues__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6irQWUQE$ 

Maybe pyqgis repo should be renamed to pyqgis-documentation or so?

Regards,

Richard Duivenvoorde



------------------------------

Message: 2
Date: Thu, 4 Mar 2021 12:17:17 +0100
From: Benjamin Jakimow <benjamin.jakimow at geo.hu-berlin.de>
To: qgis-developer at lists.osgeo.org
Subject: Re: [QGIS-Developer] [PyQGIS] Unexpected crash using:
	QgsFeatureRenderer.symbolForFeature()
Message-ID: <9c307c86-4a74-6ca3-db51-c29bde2ec80b at geo.hu-berlin.de>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"

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://urldefense.com/v3/__https://github.com/qgis/pyqgis/issues/68_
> _;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6t
> __RiXG$ >
>
> Thanks a lot
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: 
> https://urldefense.com/v3/__https://lists.osgeo.org/mailman/listinfo/q
> gis-developer__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3n
> Dd_XZbNJv6Ac6rPFD9Q7$
> Unsubscribe: 
> https://urldefense.com/v3/__https://lists.osgeo.org/mailman/listinfo/q
> gis-developer__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3n
> Dd_XZbNJv6Ac6rPFD9Q7$

--
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://urldefense.com/v3/__https://hu-berlin.de/eo-lab__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6i6RSCvm$ 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://urldefense.com/v3/__http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210304/1691cbf8/attachment-0001.html__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6uCqWUTN$ >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5422 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://urldefense.com/v3/__http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210304/1691cbf8/attachment-0001.bin__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6te6TV1S$ >

------------------------------

Message: 3
Date: Thu, 4 Mar 2021 14:50:11 +0100
From: Martin Dobias <wonder.sk at gmail.com>
To: Eric Younkin - NOAA Federal <eric.g.younkin at noaa.gov>
Cc: qgis-dev <qgis-developer at lists.osgeo.org>,  Barry Gallagher - NOAA
	Federal <barry.gallagher at noaa.gov>
Subject: Re: [QGIS-Developer] PYQGIS - OpenGL in QgsPluginLayer
Message-ID:
	<CAC2XbFfWuJKY7_vNSq4nvw0HQa2B6VQEg_LhPqbAhi5CkQSm=A at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Eric

I don't know about the S57 driver, best to ask on the gdal mailing list about that...

As for QML format... you should not try to read/write raw XML data of QML
files: although that happens rarely, the format may change between versions of QGIS as the schema is not guaranteed to be stable and it should be considered as an implementation detail of QGIS. To prepare QML files, the two preferred ways are:
1. GUI - use QGIS app to set up styling of the map layer 2. Python API - use PyQGIS library to create renderer (e.g.
QgsSingleSymbolRenderer) and symbol (e.g. QgsMarkerSymbol) objects and assign them to a map layer Then to save the QML file, you can again either use GUI (layer properties
dialog) or use Python API (QgsMapLayer.saveNamedStyle(...))

Regards
Martin


On Wed, Mar 3, 2021 at 7:02 PM Eric Younkin - NOAA Federal < eric.g.younkin at noaa.gov> wrote:

> All,
>
> This is very useful, thanks.  The S57 driver does appear to give the 
> layers by names that I recognize:
>
> INFO: Open of `C:\collab\dasktest\data_dir\13238_FFF.000'
>       using driver `S57' successful.
> 1: DSID (None)
> 2: LNDARE
> 3: LNDELV
> 4: SBDARE
> 5: UWTROC (Point)
>
> I've found the QML format spec here
> <https://urldefense.com/v3/__https://docs.qgis.org/3.16/en/docs/user_m
> anual/appendices/qgis_file_formats.html__;!!KbSiYrE!z9gWU7RU0cugBA6s2K
> KJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6jfDAuR6$ >, but is there any guidance on starting from scratch?  Thanks again for all the help.
>
> Eric
>
>
> On Wed, Mar 3, 2021 at 12:38 PM Martin Dobias <wonder.sk at gmail.com> wrote:
>
>> Hi Eric
>>
>> On Wed, Mar 3, 2021 at 5:48 PM Eric Younkin - NOAA Federal < 
>> eric.g.younkin at noaa.gov> wrote:
>>
>>> Thanks for the quick reply.  This is for NOAA nautical chart 
>>> symbology, following the s57/s52 spec.  You can see the symbology in 
>>> the online viewer here <https://urldefense.com/v3/__https://www.nauticalcharts.noaa.gov/ENCOnline/enconline.html__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6iITpKcA$ >.
>>> It is basically a very complex spec that we generated for display in 
>>> a wxPython widget a long time ago using GDAL 1.x commands.  S57 is 
>>> already an existing OGR driver, although I do not know what exactly that driver does.
>>> I do know that it does not somehow generate the symbology of the 
>>> data for you to then render.
>>>
>>> The vector data would be a combination of area/line/point features, 
>>> and I don't think it would be a fit for the Mesh layer.
>>>
>>> We'd like to make this symbology available in QGIS, so that users 
>>> can drag in a s57 file and view the chart.  You can use one of our 
>>> WMS services, but having the file support would be useful.  Ideally 
>>> in a plugin layer, so that I can also use it in our other apps that 
>>> use PYQGIS QgsMapCanvas widgets.
>>>
>>
>> Thanks for more background. In this case the mesh layer indeed is not 
>> useful. I have not worked with S57 before, but if there is OGR driver 
>> available, it should be relatively easy to load and style the data 
>> without a plugin layer. You do not need to rely on styling provided 
>> by OGR (if provided at all). It looks like you only need to load the 
>> data as a bunch of vector layers using OGR (one for each object type) 
>> and then apply styling to those individual layers. Styling of vector 
>> layers in QGIS is fairly strong, with features like rule-based 
>> rendering, data-defined properties and geometry generators you can handle even very complex styles.
>> After preparing individual styles for vector layers, you can save 
>> them to .qml files, and then your plugin would have just a simple 
>> task of taking the input file(s), load layers and apply saved styles.
>>
>> I would resort to writing a custom plugin layer only when when all 
>> other options fail - it is more complex, and generally the user 
>> experience is not great.
>>
>> Regards
>> Martin
>>
>>
>
> --
> Eric Younkin
> Physical Scientist
> NOAA OCS, Hydrographic Systems and Technology Branch
> 1315 East-West Highway
> N/CS11, Room 6604
> Silver Spring, MD 20910
> Office: 240-847-8208
> Cell: 828-331-8197
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://urldefense.com/v3/__http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210304/7974f167/attachment.html__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6mVyWs4p$ >

------------------------------

Subject: Digest Footer

_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org
List info: https://urldefense.com/v3/__https://lists.osgeo.org/mailman/listinfo/qgis-developer__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6rPFD9Q7$
Unsubscribe: https://urldefense.com/v3/__https://lists.osgeo.org/mailman/listinfo/qgis-developer__;!!KbSiYrE!z9gWU7RU0cugBA6s2KKJdTYVU2pQZuWdUTNDxYT8jc3nDd_XZbNJv6Ac6rPFD9Q7$ 


------------------------------

End of QGIS-Developer Digest, Vol 185, Issue 18
***********************************************


More information about the QGIS-Developer mailing list