Ribasim icon indicating copy to clipboard operation
Ribasim copied to clipboard

write QGIS style to GeoPackage

Open visr opened this issue 2 years ago • 4 comments

Currently the Ribasim QGIS plugin applies styling to the layers on loading a model.

It would be nice if we could get the styling information out of the plugin and into the GeoPackage itself. That way the plugin does not need to be used for a good looking label. QGIS supports saving styling information to the GeoPackage. I think this is QGIS specific, and not sure how/if the GeoPackage spec says anything about it (it seems not).

It's worth looking into if we can get ribasim-python to write this information to the GeoPackage.

visr avatar Sep 21 '23 11:09 visr

In QGIS layer properties under "Style" you can save styles as QGIS QML Style File, SLD Style File, or In Database (GeoPackage). Choosing the latter adds a layer_styles table with one row per layer, and a styleQML and styleSLD field with XML encodings of the styles.

image

We can save these few hundred lines (for Node) of style encodings in the code and just add them (and update them visually in QGIS), or use a tool like pySLD to create them from code.

Edit: this works: https://github.com/Deltares/Ribasim-NL/issues/4#issuecomment-1730983175

visr avatar Sep 21 '23 12:09 visr

I would prefer not to remove the code, as you never know if you receive old files that don't contain the styling. And at the same time, if you want to update your styling with a new release of your plugin, wouldn't you want your geo files to be updated automatically as well? If you save the information in the package, they are stuck there.

deltamarnix avatar Nov 21 '23 10:11 deltamarnix

Here a QML style for 'Basin / area' styling by @DanielTollenaar, with graduated semi transparent blues.

basin_area.qml.txt

visr avatar Mar 11 '24 10:03 visr

If you save the information in the package, they are stuck there.

True, but we currently only support using the set of components together for the same Ribasim release. We may support upgrading models in the future, and if we do this we could decide to upgrade the style as well.

visr avatar Mar 11 '24 10:03 visr

Is the styling part of any official specification? It's probably quite stable since changing it would break people's styling made with older QGIS versions. I just know that I made the terrible decision in the past to try and generate a QGIS project file directly as an XML, and we found out the hard way that they aren't stable at all.

By the way, I don't think you'd want to remove the code from the plugin: whether you setup a model in QGIS or via ribasim-python, you want styling in both cases. Inside the plugin, the most straightforward way is to set it up as is works now, but then export it to the geopackage as styling.

In ribasim-python, you're always forced to generate the XML yourself.

Huite avatar Aug 06 '24 08:08 Huite

In https://www.geopackage.org/extensions.html there is the Styling and Symbology Extension. Though the fact that that is an archived repository with a notice "This subsection is under discussion and may change radically." is not very reassuring.

But probably if we do this we may still want to have an option in Ribasim Python and/or the QGIS plugin to reset the style to the current Ribasim style. We just store it in the GeoPackage to have a better user experience for non-plugin users, and to give them more freedom to modify the style and retain that.

visr avatar Aug 06 '24 12:08 visr