2

I have a shapefile with points that are joined to the closest twenty points from another shapefile. The joined shapefile has columns from the original shapefile: name (ID), elevation (Z), name from joined shapefile (name) and elevation from the joined shapefile (Z2).

So twenty rows have the same ID and name but differing Z and Z2. I would like to use the field calculator to return the row that has the smallest absolute difference between Z and Z2 with the matching ID and name.

Using a case statement in the qgis field calculator I can get all the results to return the difference in a new column:

CASE WHEN "Name" = "ID" THEN abs("Z" - "Z2") END 

but I would like only the smallest value to return.

1
  • 1
    Take a look at minimum expression Commented Dec 19, 2019 at 19:57

1 Answer 1

2

If you would like to return the smallest absolute value, you can take the minimum of each Name group by using the minimum function like so:

case when "Name" = "L1_ID" then minimum(abs("L1_Elev" - "Elev2"), "Name") end 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.