4

From a layer of points with the "CLASS" field reported with 3 different values, I apply the following expression to draw the concave polygon for each different value:

concave_hull(
            collect(
                $geometry,
                group_by:=overlay_nearest(@layer,"CLASS"))
                ,0.2)

Next, I use an expression to label the percentage of points within each concave hull polygon:

round(
with_variable(
    'num',
    concave_hull(
            collect(
                $geometry,
                group_by:=overlay_nearest(@layer,"CLASS"))
                ,0.2),
    aggregate(
        @layer,
        'count',
        1,
        within ($geometry, @num) or intersects ($geometry, @num)
    )
)

/ count('')  * 100.0,0) || ' %'

As can be seen, the total value is 103 % because it seems that there is a point that is count by duplicated in two different concave hull polygons:

enter image description here

How could I fix the label expression so that it takes this possibility and so that the percentage is balanced?

1
  • 1
    If I understood you correctly, you create the polygons based on the class field. So why don't you use the same class field to calculate the percentage?
    – Babel
    Oct 23, 2023 at 7:09

1 Answer 1

4

As you want to number the points per hull and the hull is based on the value in the class field, you can base your expression on this and don't have to complicate yourself with the hull's geometries:

round (count (class,group_by:=class) / count (class) * 100, 0)

enter image description here


By the way, better construct your hull with a simpler expression:

concave_hull(
    collect(
    $geometry,
    group_by:="class"),
    0.2
)

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.