# Calculating distance betweeen classified points in QGIS

I got two sets of points.

1. The first set has a unique `"ID"`
2. The second set references to this `"ID"` (one-to-many).

So I merged the two sets. Now every point in the joined table has the `"X"` and `"Y"` coordinates from the related first set.

``````Name;ID;X;Y;X_2;Y_2;Distance
``````

Every `"X"` and `"Y"` is unique but `"X_2"` and `"Y_2"` repeats from a given set.

Now I would like to calculate the distance between `(X,Y)` and `(X_2,Y_2)` in the new column for each row.

I tried `distance()` but I'm way too new in Python to get it working.

I also tried some tools like Distance Matrix, but I got results for all distances (or to the number defined) but not only to the distances in one row. Or between Points sharing the same `"ID"`.

• Which software are you using? Dec 4, 2018 at 7:29
• The software is QGIS Dec 4, 2018 at 7:42
• This topic Calculate distance between two points with QGIS 2.14.0 can also help you Dec 4, 2018 at 7:55
• Yes, thanks. Ive seen it. I cant install "Connect Points". I got QGIS 3.0.3. I cant find the Plug-In in the menu plus I cant install the download. As I understood the post (i read before asking my question) its not matching my problem perfectly. Im modifying a few 100k features. And Im looking for a quick and stable solution. So maybe a short python script could help me? Dec 4, 2018 at 8:00
• Thank you for posting another helpful topic! But I already read this topic (I read a lot of topics before posting here). Its not fixing my problem :( Dec 4, 2018 at 8:04

In the Field Calculator, please try:

``````distance(make_point("X", "Y"), make_point("X_2", "Y_2"))
``````

The function `distance()`:

Returns the minimum distance (based on spatial ref) between two geometries in projected units.

``````distance(geom_from_wkt('POINT(' + "X1" || ' ' || "Y1" + ')'), geom_from_wkt('POINT(' + "X2" || ' ' || "Y2" +')'))