How can I write an expression to update the area of polygons and lengths of features automatically as well as the sum of the areas and lengths. I am using QGIS 3.16.7 and the data format is OGR library.
Let's assume there was created a feature and calculated an
"area" attribute for it
For catching changes done to that feature i.e. automatically updating the area, please set up some defaults through
RMC > Properties > Attribute Form > Fields > area > Defaults
$area as the 'Default value' as well as ticked the 'Apply default value on update' and clicked Apply.
So, now after modifying feature's geometry, it's area attribute will be updated automatically.