# Projecting points on line and calculating distance from line start

I have

• a vector layer with a number of points which correspond to magnetic targets

The task is to project the points on the axis and then calculate the distance of each projected point from the start of the axis. Ideally, I would like the calculated distance to be on the same table as the points so I can know which point each distance refers to.

Moreover, it would be nice to know the perpendicular distance of each point from the reference axis. A picture of the above problem is also presented below. Start the Field Calculator on your point layer's attribute table.

Create a new field by an expression below:

``````line_locate_point(geometry:=geometry(get_feature('NaMy_FSR', 'id', '1')), point:=\$geometry)
``````

Assuming:

• Your line layer name is : `NaMy_FSR`
• The line has an attribute value `1` in the `'id'` field. (You can use any field to distinguish the line).

[EDIT]

As to the distance `the perpendicular distance of each point from the reference axis`;

Not sure if this works, but will you try:

``````distance(closest_point(geometry(get_feature(‘NaMy_FSR’, ‘id’, ‘1’)), geometry), \$geometry)
``````

[revision]

``````distance(closest_point(geometry(get_feature(‘NaMy_FSR’, ‘id’, ‘1’)), \$geometry), \$geometry)
``````
• Is there a way to obtain the projection distance from the line ? – Pand Jan 10 at 12:28
• Hi @stamatis Yes, I think it is possible. Will you post a new question or edit your current question to include this additional requirement? – Kazuhito Jan 10 at 12:38
• Question edited. Looking forward for the answer :) – Pand Jan 10 at 12:47
• @stamatis Added another syntax in `[EDIT]` section. Hopefully it works, but other specialists at this board may help you better. – Kazuhito Jan 10 at 12:53
• @stamatis Both questions are interesting, definitely. Will you post them as new questions? For the first one, I recommend to look into `azimuth()` function. I have no idea about the latter one, which would require experts' help. – Kazuhito Jan 10 at 13:31