I have a points layer with 50+ points in it, and another point layer with only one point in it (a centroid). These points are categorised in 4 groups (labeled 0-3).

I used distance matrix to work out the distance from the points to the centroid, which are now in the points layer table.

I want to:

a) Take the value from the Observation column for the closest point for each of the 4 groups

b) I want to find the difference* in the value between group 0 and 2, and 1 and 4, so I end up with two values at the end.

*In excel this is calculated as ABS(a1-a2) for example.

An example table below:

Point   Observation Distance    Group
1   23  4   1
2   14  12  1
3   5   54  1
4   54  2   1
5   7   32  2
6   87  1   2
7   32  78  3
8   45  45  3
9   8   89  4
10  5   3   4

I've made some progress; I figured out that I can select the nearest point for each group by using Select By Expression:

Distance = minimum("Distance", group_by:="Groups", filter:= "Groups" = 1)

changing 1 for 1,2,3, 4 etc.

But then how to do the rest of the calculation?

1 Answer 1


I solved this by using Distance Matrix (Standard NxT method) to create a points layer with a column for distance from a Centroid, and then joining those attributes to the original shapefile. I double checked the distance using the ruler and it matched.

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.