2

Is there a way to save virtual fields (with their expression) a layer definition file without them becoming static fields?

I have about a dozen virtual fields in many tables with complex expressions, which need to be replicated in about another 20+ projects. I would really like to find a way that I can replicate the virtual fields into the other projects without needing to recreate and copy/paste the expressions for every single virtual field.

1

Virtual fields are part of the layer's style. Styles can be transferred from one layer to another.

  • Within the same QGIS project, you can copy/paste style from one layer to another. Right click on the layer name in the Layer panel > Styles > Copy/Paste style > Fields.

enter image description here

  • To transfer a style from one project to another, save the layer's style as a QGIS QML style file. Layer properties > symbology > style > save/load style.

enter image description here

Note: In QGIS 3, you can transfer individual parts of the style. QGIS 2.18 only allows you to transfer the entire style.

  • Thanks! That's an ideal solution - unfortunately for these projects we're still using 2.18 – CEL-ma Feb 5 at 15:09
  • For multiple projects in QGIS 2.18, probably the best method is to save the style (with virtual fields) as the default style for that layer. Whenever you add that layer to a new project, it will automatically load with that style. – csk Feb 6 at 17:43
  • Or you can store the expression in a string field in the attribute table, and use the eval() function in the Field Calculator. gis.stackexchange.com/questions/311279/… – csk Feb 6 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.