I have a number of points (grey points in attached picture) around a reference point (red point in picture). I need to export X,Y data corresponding to the horizontal and vertical distance in meters of these points from the reference point. I.e. X,Y coordinates relative to the reference point.

Is there a way of doing this directly through QGIS 3.16?

enter image description here

  • A loop in Python will do the trick. How do you want your export to work? Jan 27, 2021 at 12:32

2 Answers 2


Create a new attribute x_distance and y_distance in with field calculator on the layer with the grey points, using this expression for x (change x with y for y distance and instead of ref_point include the layer name of your reference point). Than export the layer:

$x -  x (
    geometry (
        get_feature_by_id ( 

Enclouse the expression with abs () to get the absolute value (e.g. 150 instead of -150).

Screenshot: lines from each point with the calclulated horizontal and vertical distance to the reference point. Red line highlighted as sample: enter image description here


Same solution as above, but with less fancy code and more manual steps.

Step 1: Make sure your layers use the same CRS.

Step 2: Go grab the coordinates of the red point ( $x and $y). Either save them to an editor, or attach them to your point.

Step 3: Attach the values you grabbed to you other point layer by creating new columns x_red and y_red by "hardcoding" the values of x and y you grabbed. This is a simple write the coordinate down-code.

Step 4: Calculate the difference using $x - x_red (or $y - red_y accordingly).

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.