You can use an expression like the one that follows, concatenating four different elements using pipes (||
) to "stick" them together: text-element poly_
(line 1), the id of the polygon the points are within (line 2), the text element _item_
(line 3) and the id of the point (line 4). Use this to create a new attribute with field calculator (Replace 'polygon'
with the name of your polygon layer):
'poly_' ||
array_first ( overlay_within( 'polygon', $id)) ||
'_item_' ||
$id
This preserves the unique id (point item no.) of the points. If it should start from 1 for each polygon, the expression is a bit more complicated:
'poly_' ||
array_first ( overlay_within( 'polygon', $id)) ||
'_item_' ||
to_string (array_find (array_agg (array_first (overlay_within ('polygon', $id))||'_'||-$id,array_first (overlay_within ('polygon', $id))),array_first (overlay_within ('polygon', $id))||'_'||-$id)+1)
Screenshot 1: the first expression used here directly in the label field that dynamically creates the label text:
Screenshot 2: the second expression, numbering the items from 1 in each polygon. The number of points per polygong is varying:
Edit
For the problem rised in the comment, use this expression:
array_first ( overlay_within( 'distribution_area', $id)) ||
'-MST12-' ||
to_string (array_find (array_agg (array_first (overlay_within ('distribution_area', $id))||
-$id,array_first (overlay_within ('distribution_area', $id))),array_first (overlay_within ('distribution_area', $id))||-$id)+1)