# QGIS : Sequential number assigning of points from geometry of nearby line layer with same attribute

I have created an example project in QGIS to help illustrate what I am having difficulty with. Using the field calculator, I would like to automate assigning sequential numbers to my points layer according to their position in relation to the 0 vertices point of my line layer. The points do not necessarily intersect with the line and the distance from the vertices point does not necessarily increase. Both the points and the line share a connecting identical attribute, in this case "name" is 'a'. Automating this would be a massive help because i have ~1500 points and 70 lines to put into sequence.

Anyone know how to do this?

The result should look like this :

Assuming your point layer has a field `point_att` that corresponds to the field `line_att` in your line layer (named `line_layer`), and `line_att` is unique, as in the image below.

Try this expression on your point layer using Field Calculator or in the Labels expression:

``````array_find(
array_agg(\$id,
"point_att",
order_by:= line_locate_point(
geometry(get_feature('line_layer','line_att',"point_att")),
\$geometry)
),
\$id)
+1
``````

Result:

Explanation:

This is a variation of this answer I posted about using Field Calc to custom sort by another field.

Here, the `array_agg()` function first groups together the `\$id` values of all other points that correspond to the same matching line (= has the same `point_att` value), into an array.

Then instead of sorting that array by another field in the dataset per the linked answer, this expression sorts the array by each point's relative position along the matching line (`line_locate_point()`), calculated on the fly.

The final part is the same; for each feature return its position in that array using `array_find()`. Then add `+1` at the end so that the sequence starts from 1.