I wondered if I could add virtual fields to the feature tables of a number of polygon layers in a QGIS 3 project (or a geopackage).

As an example, I would like to add the virtual field area (km²) as round($area/1000000, 2) to ten polygon layers stored in a geopackage.

Is there a QGIS way of doing it? If not, any leads if I do this from R? (I don't use Python.)

  • This seems to be a use case to migrate the AutoFields plugin to QGIS 3 and extend it to support Virtual Fields. AutoFields can help to configure a large number of automatic values at once. If you'd like to help to make it possible, feel free to open a feature request at the GitHub repo. – Germán Carrillo Aug 24 '20 at 13:32

Open the attribute table of your polygon layer, select field calculator and check the box "create virtual layer". Than just paste the expression to calculate the area. Define a name for your new field and select the field type.

enter image description here

  • Thanks, I knew that. The question is: how to do that to multiple layers or a whole geopackage full of polygons at once? – aae Aug 24 '20 at 11:13

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.