3

In QGIS 3.16.8-Hannover I have a layer with polygons and I have a layer with points. Each polygon contains a certain number of points, I would like to assign a number to each point in sequential order in the attribute column "Sequence".

'Polygon A' - Has 10 points, in this case, I would have point with "Sequence" value of 1, then a point "Sequence" value of 2, and so on up to 10.

'Polygon B' - has 12 points, it would be the same as above just it would go up to 12 instead.

1

1 Answer 1

6

Create the "Sequence" attribute with this expression using the Field Calculator:

if(overlay_within('polygon'), -- name of the polygon layer
    array_find(
        array_agg(
            "id", -- id field in the point layer
            group_by:=overlay_within('polygon', "id") -- any field from the polygon layer
            ),
        "id" -- id field in the point layer
        ) + 1,
    NULL)

References:

2
  • "id", -- id field in the point layer Can it be fid? Commented Nov 15, 2022 at 7:59
  • 1
    @Ghostwriter84 yes, of course!
    – Taras
    Commented Nov 15, 2022 at 8:19

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.