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.

Taras
  • 32,823
  • 4
  • 66
  • 137

1 Answers1

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:

Taras
  • 32,823
  • 4
  • 66
  • 137