Skip to main content
Solved

Use NeighborFinder to find the Candidate that has an ID that is present in 2 possible columns in the Base dataset

  • August 8, 2023
  • 2 replies
  • 22 views

I have two point datasets, GPoints (~100 points) and OPoints (~1000 points), and I want to find the nearest neighbor for each GPoints entry. However, the nearest neighbor from OPoints must have an ID that matches the values from 2 possible columns in GPoints. In this case the column names are id1 and id2.

 

E.g.The first entry in GPoints has values of id1 = 9001 and id2 = 9005. Therefore the nearest neighbor from OPoints must have an id of 9001 or 9005 (whichever is closest to the entry in GPoints current being analyzed). In SQL this would be WHERE OPoints.id = GPoints.id1 OR OPoints.id = GPoints.id2.

Best answer by geomancer

Use a NeighborFinder without Number of Neighbors to Find (but you may want to set a Maximum Distance), and enable Generate List (select attribute ID). Next use 2 ListSearchers (one for ID1, one for ID2), and copy the found list element with prefix ID1_ and ID2_ respectively. Finally use an AttributeManager: if ID1_distance <= id2_distance copy the ID and distance of ID1, else copy the ID and distance of ID2.

NeighborFinder_OPoints

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

geomancer
Evangelist
Forum|alt.badge.img+58
  • Evangelist
  • 932 replies
  • Best Answer
  • August 8, 2023

Use a NeighborFinder without Number of Neighbors to Find (but you may want to set a Maximum Distance), and enable Generate List (select attribute ID). Next use 2 ListSearchers (one for ID1, one for ID2), and copy the found list element with prefix ID1_ and ID2_ respectively. Finally use an AttributeManager: if ID1_distance <= id2_distance copy the ID and distance of ID1, else copy the ID and distance of ID2.

NeighborFinder_OPoints


  • Author
  • 1 reply
  • August 8, 2023

Use a NeighborFinder without Number of Neighbors to Find (but you may want to set a Maximum Distance), and enable Generate List (select attribute ID). Next use 2 ListSearchers (one for ID1, one for ID2), and copy the found list element with prefix ID1_ and ID2_ respectively. Finally use an AttributeManager: if ID1_distance <= id2_distance copy the ID and distance of ID1, else copy the ID and distance of ID2.

NeighborFinder_OPoints

Thanks geomancer, that works perfectly! Lists seem very powerful and versatile, I will have to look into them more.