I have a layer of output areas in a city, with two fields for "TotalArea" and "NaturalArea", and I'd like to include a field in the same shapefile that is essentially "NaturalArea/TotalArea". Is there a way to do this?

What if some output areas have null entries for "NaturalArea"?


1 Answer 1


You have 2 choice (works from 2.6 version and further):

  • Either you create a new permanent real field "RatioNat" for example, then use the Field Calculator, then you enter "NaturalArea"/"TotalArea". QGIS will store the result in the new column. The downside is that it will not change if your geometry changes, but it will keep it in the layer table. You will have to rerun the field calculator to have updated values.
  • Either you create a new virtual real field "vRatioNat" for example still through the Field Calculator, but checking "Virtual field", where you input your formula. The good thing is that your values will change if you change the content of the other fields.

For your info, a quote from QGIS manual :

A virtual field is a field based on an expression calculated on the fly, meaning that its value is automatically updated as soon as the underlying parameter changes. The expression is set once; you no more need to calculate again the field if underlying values change. For example, you may want to use a virtual field if you need area values to be calculated during a digitizing process (creating, merging, spliting features) or to calculate a duration that needs to be updated from time to time.

The downside is that :

Virtual fields are not permanent and thus not saved in the layer attributes. They are however saved in the project they were created. To make a field virtual it must be set at the creation of the field and the expression used can’t be changed later


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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