2

I have a point geometry layer with which I have built an expression that creates a convex_hull for the features closest to the features that have a given value:

convex_hull( 
    collect(
        $geometry,
        group_by:=overlay_nearest(
            'PT',
            $id,
            "idff" = 1
        )
    )
)

I get this satisfying result:

enter image description here

Now I am trying to calculate the number of points that are part of each convex_hull (including those with value 1 and value 2), with the goal of labeling the centroid of each convex_hull with this calculation. For this I am trying to develop an expression in this sense, but as you will see at the moment it is not working.

What corrections or new approach should I give to this expression?

And how could I calculate the value expressed in percentage?

aggregate(
    layer:='PT', 
    aggregate:='count', 
    expression:=within(
        $geometry, 
        geometry(@parent)
    ),
    filter:=overlay_nearest(
        'PT',
        $id,
        "idff" = 1
    )
)

enter image description here

1 Answer 1

3

Use this expression:

with_variable(
    'ch',
    convex_hull(
        collect(
            $geometry,
            group_by:=overlay_nearest(
                'PT',
                $id,
                "idff" = 1
            )
        )
    ),
    aggregate(
        'PT',
        'count',
        1,
        within($geometry, @ch) or intersects($geometry, @ch)
    )
)

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.