The question
Using QGIS expression, it can occur that you want to identify the geometry-type of a layer (point, line or polygon? Multiple or single part?). This can be the case to write an expression that works for different kind of geometry types, using an if-clause - pseudocode: if point, do A, if line, do B, if polygon, do C
.
See here for an example (go to the expression at B. Get list of all the angles of a line or polygon).
What I tried
I looked if there is a variable of the kind @layer_type
, but there is not. There are variables for @layer_name
or @layer_crs
, but not for the geometry type of the layer (see screenshot).
As in the example above, a workaround is to find out if a geometry is a polygon or not to use if(num_rings($geometry) is null, 1, 0)
: returns 0 for polygons, 1 for lines and points.