Performing lookup based on euclidean distance

Dear all,

I want to join two tables based on a distance based lookup. e.g.

Table 1
image

Table 2
image

Output:
image

Any pointers would be of great help !

cheers

Hi,

I think this is possible by using a loop:

Untitled

distance.knwf (33.3 KB)

:blush:

2 Likes

Nice @armingrudd , using the Crossjoiner node for the two tables and than do some math is also an possibility.

1 Like

I think this is not a good idea @HansS.
After cross join and calculating the distance, you have to filter the table to keep names from the first table with minimum distance. To do this and at the same time retaining the other columns, you have to use Group Loop Start. So it gets longer and more complex.
Or maybe I’m missing something?

:blush:

P.S. I edited my first reply and removed the last sentence about using loop on the table with less number of rows. Actually it’s not possible to use exactly the same approach on the other table. Sorry if this misled you.

Thanks a lot !
Can I write a custom distance measure here

using any programming language ?

You can use the functions available in the node.
In Column Expressions you can use the available functions or JavaScript syntax.

If you need to use Python, Java, R ,… you can use the corresponding snippet nodes.

:blush:

2 Likes

Hi @armingrudd

I think your missing something …?! because after the Mathformula, I do a sort on name and distance. With a Groupby I take the first row (smallest) for the columns needed. See the wf pythagoras.knwf (24.5 KB)
distance

1 Like

Very interesting idea @HansS. :+1:

Just I think it’s better to add an ID column to the first table and use it instead of the name column for grouping so you won’t miss anything in case there are multiple instances of the same name in the first table.

:blush:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.