[QGIS-Developer] PYQGIS - OpenGL in QgsPluginLayer

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[QGIS-Developer] PYQGIS - OpenGL in QgsPluginLayer

Eric Younkin - NOAA Federal
Hello,

Looking for some advice.  We have a need to use OpenGL to draw the symbology associated with some vector data.  All of our code uses OpenGL 1.x.  I was thinking we could use the QOpenGLWidget and the QgsPluginLayer to add our OpenGL rendered symbology to a QgsMapCanvas as a new layer.  

Is this possible?  Is there an example anyone knows of that is kind of similar to this idea?  Or is there a better way to approach this problem?

Thanks,
Eric

--
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

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

Martin Dobias
Hi Eric

On Wed, Mar 3, 2021 at 3:48 PM Eric Younkin - NOAA Federal <[hidden email]> wrote:
Looking for some advice.  We have a need to use OpenGL to draw the symbology associated with some vector data.  All of our code uses OpenGL 1.x.  I was thinking we could use the QOpenGLWidget and the QgsPluginLayer to add our OpenGL rendered symbology to a QgsMapCanvas as a new layer.  

Is this possible?  Is there an example anyone knows of that is kind of similar to this idea?  Or is there a better way to approach this problem?

Could you please provide some more details regarding the symbology you would like to get rendered? A screenshot would help a lot...

If you plan to use mesh-based weather data, maybe what you are trying to do is already possible with the mesh layer in QGIS out of the box (e.g. display of arrows, streamlines, trace animation), or there is only small amount of extra work do be done in QGIS core to achieve that.

As for OpenGL approach (it looks like you already have some existing code you would like to adapt to QGIS)... are you looking just at 2D rendering or 3D rendering as well? I know some time ago for QGIS 2.x Vincent Mora has created a plugin layer that used OpenGL to render to offscreen image and then draw it in map canvas [1] which involved some hacks. With QOpenGLWidget approach I would be quite cautious as it may not work well, or have some strange issues on different platforms. For example, I _think_ the QOpenGLWidget can't be semi-transparent (but I may be wrong), so mixing its content with the rest of the map could be quite tricky...

Regards
Martin


_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

Eric Younkin - NOAA Federal
Hi Martin,

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.  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,
Eric

On Wed, Mar 3, 2021 at 11:00 AM Martin Dobias <[hidden email]> wrote:
Hi Eric

On Wed, Mar 3, 2021 at 3:48 PM Eric Younkin - NOAA Federal <[hidden email]> wrote:
Looking for some advice.  We have a need to use OpenGL to draw the symbology associated with some vector data.  All of our code uses OpenGL 1.x.  I was thinking we could use the QOpenGLWidget and the QgsPluginLayer to add our OpenGL rendered symbology to a QgsMapCanvas as a new layer.  

Is this possible?  Is there an example anyone knows of that is kind of similar to this idea?  Or is there a better way to approach this problem?

Could you please provide some more details regarding the symbology you would like to get rendered? A screenshot would help a lot...

If you plan to use mesh-based weather data, maybe what you are trying to do is already possible with the mesh layer in QGIS out of the box (e.g. display of arrows, streamlines, trace animation), or there is only small amount of extra work do be done in QGIS core to achieve that.

As for OpenGL approach (it looks like you already have some existing code you would like to adapt to QGIS)... are you looking just at 2D rendering or 3D rendering as well? I know some time ago for QGIS 2.x Vincent Mora has created a plugin layer that used OpenGL to render to offscreen image and then draw it in map canvas [1] which involved some hacks. With QOpenGLWidget approach I would be quite cautious as it may not work well, or have some strange issues on different platforms. For example, I _think_ the QOpenGLWidget can't be semi-transparent (but I may be wrong), so mixing its content with the rest of the map could be quite tricky...

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

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

SPeillet

Hi Eric,

As Martin said, Vincent Mora created a plugin layer in QGIS 2.x to render OpenGL layer. This plugin layer was designed to render a mesh layer as it was not available yet in QGIS. So only this kind of layer has been developped, but you should be able to use the OpenGlLayer class to create other kind of layer. Since last year, I inherited projects that depend of that plugin layer and migrated the meshlayer on QGIS 3.x . I juste pushed the recent update on the gitlab.com repository (Oslandia left the github.com one) : https://gitlab.com/Oslandia/qgis/meshlayer

The latest update is necessary to use the meshlayer on QGIS >= 3.14 .

Regards

Sébastien

On 03/03/2021 17:48, Eric Younkin - NOAA Federal wrote:
Hi Martin,

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.  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,
Eric

On Wed, Mar 3, 2021 at 11:00 AM Martin Dobias <[hidden email]> wrote:
Hi Eric

On Wed, Mar 3, 2021 at 3:48 PM Eric Younkin - NOAA Federal <[hidden email]> wrote:
Looking for some advice.  We have a need to use OpenGL to draw the symbology associated with some vector data.  All of our code uses OpenGL 1.x.  I was thinking we could use the QOpenGLWidget and the QgsPluginLayer to add our OpenGL rendered symbology to a QgsMapCanvas as a new layer.  

Is this possible?  Is there an example anyone knows of that is kind of similar to this idea?  Or is there a better way to approach this problem?

Could you please provide some more details regarding the symbology you would like to get rendered? A screenshot would help a lot...

If you plan to use mesh-based weather data, maybe what you are trying to do is already possible with the mesh layer in QGIS out of the box (e.g. display of arrows, streamlines, trace animation), or there is only small amount of extra work do be done in QGIS core to achieve that.

As for OpenGL approach (it looks like you already have some existing code you would like to adapt to QGIS)... are you looking just at 2D rendering or 3D rendering as well? I know some time ago for QGIS 2.x Vincent Mora has created a plugin layer that used OpenGL to render to offscreen image and then draw it in map canvas [1] which involved some hacks. With QOpenGLWidget approach I would be quite cautious as it may not work well, or have some strange issues on different platforms. For example, I _think_ the QOpenGLWidget can't be semi-transparent (but I may be wrong), so mixing its content with the rest of the map could be quite tricky...

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

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
-- 
Sébastien Peillet

Ingénieur développement
Oslandia
01.88.33.76.86
[hidden email]

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

Martin Dobias
In reply to this post by Eric Younkin - NOAA Federal
Hi Eric

On Wed, Mar 3, 2021 at 5:48 PM Eric Younkin - NOAA Federal <[hidden email]> 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.  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


_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

Eric Younkin - NOAA Federal
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, 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 <[hidden email]> wrote:
Hi Eric

On Wed, Mar 3, 2021 at 5:48 PM Eric Younkin - NOAA Federal <[hidden email]> 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.  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

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

Martin Dobias
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 <[hidden email]> 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, 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 <[hidden email]> wrote:
Hi Eric

On Wed, Mar 3, 2021 at 5:48 PM Eric Younkin - NOAA Federal <[hidden email]> 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.  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

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: PYQGIS - OpenGL in QgsPluginLayer

Eric Younkin - NOAA Federal
This is great, thanks for the info.  I believe we will be working through the GUI to do the symbolization.

Thanks,
Eric

On Thu, Mar 4, 2021 at 8:50 AM Martin Dobias <[hidden email]> wrote:
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 <[hidden email]> 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, 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 <[hidden email]> wrote:
Hi Eric

On Wed, Mar 3, 2021 at 5:48 PM Eric Younkin - NOAA Federal <[hidden email]> 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.  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


--
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

_______________________________________________
QGIS-Developer mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer