# Calculate area of geometry derived from current feature in QGIS 2.8

I'm trying to create a new field defined as the area of the convex hull of the current feature, in the Field Calculator in QGIS 2.8.

Calculating the area of the current feature is easy (\$area), and calculating the convex hull of the current feature is easy (convexHull(\$geometry)), but I can't find any way to calculate the area of that resulting geometry (as opposed to the geometry of the current feature).

I think I need to be able to either:

• Apply an area calculation to that convex hull geometry in the Field Calculator -- this is what I'd prefer; or
• Write a custom function -- there appears to be a free-standing area function in the Function Editor, but I can't figure out how to get a simple custom function defined and called properly; shouldn't need any arguments, as it's just the area of the convex hull of the current geometry; or
• Create a new layer from an interim attribute that just contains the geometry of the convex hull -- then I could calculate the areas of those features in the new layer

Any suggestions on any of these approaches?

• Haven't used this before but how about area(convex_hull(\$geometry)) where area returns the area of geometry polygon object, in this case, the convex polygon? Commented Mar 1, 2016 at 10:17
• Joseph is spot on Commented Mar 1, 2016 at 12:32
• Exactly! That was my first thought. Seems like that should obviously work, but the Output preview says that the "Expression is invalid" with a "Parser Error: syntax error, unexpected '(', expecting \$end". Commented Mar 1, 2016 at 14:56
• convexHull(\$geometry) works and returns a geometry (the function is convexHull vs. convex_hull), but area(convexHull(\$geometry)) gives the error. Seems no obvious way to operate on the resulting geometry vs. the geometry of the current feature. Commented Mar 1, 2016 at 15:13
• I've almost got the second approach, a custom function, working. I created this little script in the Function Editor: from qgis.core import * @qgsfunction(args=0, group='Custom') def AreaOfConvexHull(value1, feature, parent): return QgsGeometry.area(QgsGeometry.convexHull(feature.geometry())) In the Output preview, it displays good looking result (vs. an error). However, when I use the function to create a new attribute, I get a popup with the msg: "QgqGeometry.convexHull(): first argument of unbound method must have type 'QgsGeometry'. What am I doing wrong? So close ... Commented Mar 2, 2016 at 19:02