For those who know how powerful QGIS can be using data defined widgets and expressions almost anywhere in styling and labeling settings, it remains today quite complex to store custom data.
For instance, moving a simple label using the label toolbar is not straightforward, that wonderful toolbar remains desperately greyed-out for manual labeling tweaks
…unless you do the following:
- Set your vector layer editable (yes, it’s not possible with readonly data)
- Add two columns in your data
- Link the X property position to a column and the Y position to another
the Move Label map tool becomes available and ready to be used (while your layer is editable). Then, if you move a label, the underlying data is modified to store the position. But what happened if you want to fully use the Change Label map tool (color, size, style, and so on)?
Well… You just have to add a new column for each property you want to manage. No need to tell you that it’s not very convenient to use or even impossible when your data administrator has set your data in readonly mode…
A plugin, made some years ago named EasyCustomLabeling was made to address that issue. But it kept being full of caveats, like a dependency to another plugin (Memory layer saver) for persistence, or a full copy of the layer to label inside a memory layer which indeed led to loose synchronisation with the source layer.
Two years ago, the French Agence de l’eau Adour Garonne (a water basin agency) and the Ministry in charge of Ecology asked Oslandia to think out QGIS Enhancement proposals to port that plugin into QGIS core, among a few other things like labeling connectors or curved labels enhancements.
Those QEPs were accepted and we could work on the real implementation, so here we are, Auxiliary storage has now landed in master!
The aim of auxiliary storage is to propose a more integrated solution to manage these data defined properties :
- Easy to use (one click)
- Transparent for the user (map tools always available by default when labeling is activated)
- Do not update the underlying data (it should work even when the layer is not editable)
- Keep in sync with the datasource (as much as possible)
- Store this data along or inside the project file
As said above, thanks to the Auxiliary Storage mechanism, map tools like Move Label, Rotate Label or Change Label are available by default. Then, when the user select the map tool to move a label and click for the first time on the map, a simple question is asked allowing to select a primary key :
From that moment on, a hidden table is transparently created to store all data defined values (positions, rotations, …) and joined to the original layer thanks to the primary key previously selected. When you move a label, the corresponding property is automatically created in the auxiliary layer. This way, the original data is not modified but only the joined auxiliary layer!
A new tab has been added in vector layer properties to manage the Auxiliary Storage mechanism. You can retrieve, clean up, export or create new properties from there :
Where the auxiliary data is really saved between projects?
We end up in using a light SQLite database which, by default, is just 8 Ko! When you save your project with the usual extension .qgs, the SQLite database is saved at the same location but with a different extension : .qgd.
Two thoughts with that choice:
- « Hey, I would like to store geometries, why no spatialite instead? «
Good point. We tried that at start in fact. But spatialite database initializing process using QGIS spatialite provider was found too long, really long. And a raw spatialite table weight about 4 Mo, because of the huge spatial reference system table, the numerous spatial functions and metadata tables. We chose to fall back onto using sqlite through OGR provider and it proved to be fast and stable enough. If some day, we achieve in merging spatialite provider and GDAL-OGR spatialite provider, with options to only create necessary SRS and functions, that would open news possibilities, like storing spatial auxiliary data.
- « Does that mean that when you want to move/share a QGIS project, you have to manually manage these 2 files to keep them in the same location?! »
True, and dangerous isn’t it? Users often forgot auxiliary files with EasyCustomLabeling plugin. Hence, we created a new format allowing to zip several files : .qgz. Using that format, the SQLite database project.qgd and the regular project.qgs file will be embedded in a single project.zip file. WIN!!
Changing the project file format so that it can embed, data, fonts, svg was a long standing feature. So now we have a format available for self hosted QGIS project. Plugins like offline editing, Qconsolidate and other similar that aim at making it easy to export a portable GIS database could take profit of that new storage container.
Now, some work remains to add labeling connectors capabilities, allow user to draw labeling paths by hand. If you’re interested in making this happen, please contact us!
A full video showing auxiliary storage capabilities:
PR New Zip format: https://github.com/qgis/QGIS/pull/4845
PR Editable Joined layers: https://github.com/qgis/QGIS/pull/4913
PR Auxiliary Storage: https://github.com/qgis/QGIS/pull/5086